Today, when we look at the manual, I inadvertently see the two built-in functions Parse_url and PARSE_STR. After seeing their usage, I suddenly thought that I could use these two functions to get the parameters in the URL address. To verify my guess, I'll take the following URL as an example: https://www.baidu.com/baidu?wd= Baidu &tn=monline_4_dg&ie=utf-8
The code is as follows:
$url = ' https://www.baidu.com/baidu?wd= Baidu &tn=monline_4_dg&ie=utf-8 '; $url _info Parse_url ($url); // Print_r ($arr); Parse_str ($url _info[' query '],$query); Print_r ($query);
Here we first print out the information of the $url_info array, such as:
We see a return of four messages: protocol header, domain name, path, parameters. Here we then use the PARSE_STR function to manipulate the parameters.
Print out the array information after the PARSE_STR function is processed such as:
So we get a one-dimensional associative array with the parameter name key and the value of the parameter as the value. Also proves that my conjecture is correct.
Through this I learned the following PHP built-in functions:
Mixed parse_url ( string $url
[, int $component
=-1])
resolves the URL, returning its components . The return value is a one-dimensional associative array that returns false on error.
The first parameter is the URL address that is parsed, and the second parameter returns the array if it is not, and returns the specified value if it is established.
For example :
=============================================================================================================== ========
void parse_str ( string $str
[, array &$arr
])
Parses a string into multiple variables. No return value!
The first argument is the parsed string, and the second parameter is the array name (all parsed information is saved to the one-dimensional associative array in the array).
Examples are as follows:
$str= "First=value&arr[]=foo+bar&arr[]=baz";Parse_str($str);Echo $first;//valueEcho $arr[0];//Foo BarEcho $arr[1];//BazParse_str($str,$output);Echo $output[' first '];//valueEcho $output[' arr '] [0];//Foo BarEcho $output[' arr '] [1];//Baz
How to quickly get the parameter name and the parameter value in the URL address (when looking at the PHP manual, inadvertently see these two functions, guess can be used together.) )