Home Swift UNIX C Assembly Go Web MCU Research Non-Tech

What are the query of URL? How to parse and obtain them?

2022-07-10 | Web | #Words: 460 | 中文原版

This article is to introduce the common parameter parts in URLs and how to use common Python, JavaScript, and PHP to parse and obtain parameters. (You can click on the table of contents on the left to jump directly to the part you want to see)

What are URL parameters?

When visiting a website, you may see a ?id=1 or other parts in the format similar to ?xxx=xxx in the URL. what is this?

This part is called query (meaning question mark, very vivid) by definition, and is also called URL access parameter (URL parameter) or directly called URL parameter. Taking ?id=1 as an example, ? indicates the beginning of the parameter, id is the parameter name, and =1 indicates that the value of the parameter is 1. If there are multiple parameters, use & to separate the parameters.

Purpose and advantages of URL parameters

In terms of use, the most straightforward and broad term is: you can pass information through the URL by using URL parameters. Specifically, it can implement search queries, filters and other functions.

For example: Suppose the user enters abc in the input box and presses Enter, an address of https://www.example.com/?keyword=abc will be returned. When the user visits, the server will retrieve relevant content through the server search function through the URL parameter keyword here, and then return it to the user’s computer, so that the user can see the relevant information. There are also some websites that use the parameter id to manage their own interface. By getting the URL parameters and then retrieving them in the database, it is much more convenient.

The advantages are convenience and speed. If URL parameters are not used, it will be extremely troublesome to manage some websites or implement some functions.

How to parse URL parameters

Next, we will introduce the methods of parsing and obtaining URL parameters in different languages.

In order not to make the article too long, I have written them into separate blogs.

###Python Python is probably the easiest way. For space reasons, please refer to How Python parses and obtains URL parameters and uses

JavaScript

JavaScript is a little more cumbersome. For space reasons, please refer to How to get query of URLs in Javascript

PHP

The PHP and Python methods are similar and simple. Due to space limitations, please refer to How to get query of URLs in PHP

Swift

Some people also use Swift and are listed here. Due to space limitations, please refer to How Swift parses URLs

I hope these will help someone in need~