We all know that the pathinfo (), parse_url (), and basename () functions in PHP are URL-resolved functions, but there are also some differences. The following lists some examples, through examples, it is easier to understand the usage methods and skills of these three functions. if you need them, you can refer to them. if you are interested, let's study them together. This document describes how to use functions in php.
pathinfo()
,
parse_url()
And
basename()
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.