In the case of known URL parameters, we can use $_get to obtain the corresponding parameter information ($_get[' name ') according to our own situation; how do I get the parameter information on the URL in an unknown situation?
The first, using $_server built-in array variables
Relatively primitive $_server[' query_string ' to get, URL parameters, usually returned using this variable will be similar to the data: name=tank&sex=1
If you need to include a file name, you can use $_server["Request_uri"] (return similar to:/index.php?name=tank&sex=1)
The second, using pathinfo built-in functions
The code is as follows:
<?php
$test = PathInfo ("http://localhost/index.php");
Print_r ($test);
/*
The results are as follows
Array
(
[DirName] = http://localhost//url path
[basename] = index.php//full file name
[Extension] = PHP//filename suffix
[FileName] = = index//file name
)
*/
?>
Third, the use of parse_url built-in functions
The code is as follows:
<?php
$test = Parse_url ("Http://localhost/index.php?name=tank&sex=1#top");
Print_r ($test);
/*
The results are as follows
Array
(
[Scheme] = HTTP/What protocol to use
[Host] = localhost/host name
[path] =/index.php//Path
[query] = name=tank&sex=1//Parameters passed
[Fragment] = Top//anchor point of the back root
)
*/
?>
Fourth, the use of basename built-in functions
The code is as follows:
<?php
$test = basename ("Http://localhost/index.php?name=tank&sex=1#top");
echo $test;
/*
The results are as follows
Index.php?name=tank&sex=1#top
*/
?>
In addition, there is a regular matching process to get the desired value. This method is more accurate, the efficiency is not considered ...
Following the development of the practice of regular processing methods:
The code is as follows:
<?php
Preg_match_all ("/(\w+=\w+) (#\w+)?/I", "Http://localhost/index.php?name=tank&sex=1#top", $match);
Print_r ($match);
/*
The results are as follows
Array
(
[0] = = Array
(
[0] = Name=tank
[1] = Sex=1#top
)
[1] = = Array
(
[0] = Name=tank
[1] = Sex=1
)
[2] = = Array
(
[0] = =
[1] = = #top
)
)
*/
?>
Four examples of how PHP URL parameters are obtained