Php uses the pathinfo (), parse_url (), and basename () functions to parse the URL, pathinfobasename
This document describes how to use functions in php.pathinfo(),parse_url()Andbasename()The instance code for URL Parsing. Let's just look at the code.
The instance code is as follows:
1. Use pathinfo to parse the URL
<? $test = pathinfo("http://localhost/index.php"); print_r($test);?>
The result is as follows:
Array ([dirname] => http: // localhost // url path [basename] => index. php // complete file name [extension] => php // file name suffix [filename] => index // file name)
2. parsing using parse_url () function
<? $test = parse_url("http://localhost/index.php?name=tank&sex=1#top"); print_r($test);?>
The result is as follows:
Array ([scheme] => http // protocol used [host] => localhost // host name [path] =>/index. php // path [query] => name = tank & sex = 1 // The parameter [fragment] => top // The Anchor behind the root)
3. Use basename () for parsing
<? $test = basename("http://localhost/index.php?name=tank&sex=1#top"); echo $test;?>
The result is as follows:
index.php?name=tank&sex=1#top
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.