PHP functions PathInfo (), Parse_url (), and basename (), these three are all functions that parse the URL, but there are some differences, this article lists some examples, hope that through these examples to help you understand the three functions of the use of methods and techniques, Take a look at it:
1. Using PathInfo to parse URLs
The PathInfo function is the path, directory, or file name that gets the file.
example, the code is as follows
< $test = PathInfo ("http://www.php.cn/index.php");p Rint_r ($test); >
Code Run Result:
2, using Parse_url () function analysis
The Parse_url () function is used to parse the URL and return an associative array of parsing components, which does not detect whether the URL is legitimate and only resolves it as correctly as possible.
example, the code is as follows
< $test = Parse_url ("Http://www.php.cnt/index.php?name=tank&sex=1#top");p Rint_r ($test); >
Code Run Result:
3, using basename () analysis
The basename () function returns the file name in the path
example, the code is as follows
< $test = basename ("Http://localhost/index.php?name=tank&sex=1#top"); Echo $test;? >
Code Run Result:
"Related articles recommended":
1. Detailed php pathinfo () function get file path information
2. The PHP basename () function Gets the use of the file name
3. A detailed description of PHP parse_url () function definition and usage