This article is mainly about the use of PHP functions pathinfo()
, parse_url()
and basename()
parse the URL of the instance code, the following words do not say more directly to see the code
The instance code is as follows:
1, using PathInfo to resolve the URL
?
$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
[filename] => index//filename
)
2. Using Parse_url () function to parse
?
$test = Parse_url ("Http://localhost/index.php?name=tank&sex=1#top");
Print_r ($test);
? >
The results are as follows
Array
(
[scheme] => HTTP///using what Protocol
[host] => localhost//host name
[path] =>/index.php//Path
[ Query] => name=tank&sex=1//passed parameters
[fragment] => anchor point of Top//back root
)
3. Use basename () to resolve
?
$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
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.