It is well known that in PHP functions PathInfo (), Parse_url (), and basename (), these three are the functions that parse the URL, but there are some differences, here are some examples, it is easier to understand the use of these three functions using methods and techniques, Friends who need to be able to reference, interested in the following friends to learn together.
This article mainly introduces the PHP use of functions pathinfo()
, parse_url()
and basename()
parse the URL of the instance code, the following words do not say, directly to see the code
The instance code is as follows:
1. Using PathInfo to parse URLs
<? $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 [filenam E] = = index//file name)
2, using Parse_url () function analysis
<? $test = Parse_url ("Http://localhost/index.php?name=tank&sex=1#top"); Print_r ($test);? >
The results are as follows
Array ([scheme] + HTTP//Use what protocol [host] + localhost//hostname [path] +/index.php//path [query] = name=tank& Sex=1//transmitted parameters [fragment] = Top//anchor point of the back root)
3, using basename () analysis
<? $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
The above is the whole content of this article, I hope that everyone's study has helped.