This article mainly introduces the PHP URL parameter to obtain the way four examples, php URL parameter parsing 4 kinds of methods, the need friend may refer to under
In the case of a known URL parameter, we can use $_get to obtain the corresponding parameter information ($_get[' name ') according to our own situation; then how do I get the parameter information on the URL in the unknown case? The first, using the $_server built-in array variable The relatively original $_server[' query_string '] to get the parameters of the URL, usually returned by using this variable will be similar to the data:name=tank& Sex=1 You can use $_server["Request_uri" If you need to include a filename (return similar:/index.php?name=tank&sex=1) Second, take advantage of pathinfo built-in functions Code as follows: <?php $test = PathInfo ("http://localhost/index.php"); Print_r ($test); /* results are as follows Array ( [dirname] => http://localhost//url path [basename] => INDEX.P HP //full file name [extension] => php //filename suffix [filename] => index//file name )/?> The third, the use of Parse_url built-in functions code as follows: <?php $test = Parse_url ("Http://localhost/index.php?na Me=tank&sex=1#top "); Print_r ($test); /* results are as follows Array ( [scheme] => http//Use what protocol [host] => localhost//host name & nbsp [path] =>/index.php//path [query] => namE=tank&sex=1//Transmitted parameters [fragment] => Top//back root anchor) * *?> Fourth, using basename built-in functions &N Bsp Code as follows: <?php $test = basename ("Http://localhost/index.php?name=tank&sex=1#top"); Echo $test; /* results are as follows Index.php?name=tank&sex=1#top/?> In addition, it is through the regular matching process to get the desired value. This method is more accurate, the efficiency is not considered ... Below expand practice under the regular processing mode: code as follows: <?php Preg_match_all ("/(w+=w+) (#w +)?/I", "Http://localhost/index.php?name=tank &sex=1#top ", $match); Print_r ($match); /* results are as follows Array ( [0] => Array ( [0] => Name=tank [1] => sex=1#top ) [1] => Array ( [0] => Name=tank & nbsp &NBSP;[1] => sex=1 ) &NBSP;[2] => ArraY ( [0] => &NBS P [1] => #top )] * *?> long journey ... Still need to dig ...