PHP functions pathinfo(), parse_url() and basename(), these three are all functions for parsing URLs, but there are some differences. This article lists some examples, hoping that these examples will help everyone understand it easier. Let’s take a look at the usage methods and techniques of these three functions:
1. Use pathinfo to parse the URL
The pathinfo function is to obtain the path, directory or file name.
Example, the code is as follows
<? $test = pathinfo("http://www.php.cn/index.php"); print_r($test); ?>
Code running results:
##2. Use parse_url() function to parse
The parse_url() function is used to parse URLs and return an associative array of parsed components. This function will not detect whether the URL is legal, but will only try to parse it correctly. Example, the code is as follows<? $test = parse_url("http://www.php.cnt/index.php?name=tank&sex=1#top"); print_r($test); ?>
The basename() function returns the file name in the path
Instance, the code is as follows
<? $test = basename("http://localhost/index.php?name=tank&sex=1#top"); echo $test; ?>
The code running result:
[Related article recommendations]:1.
Detailed explanation of the php pathinfo() function to obtain file path informationDetailed explanation of the usage of the php basename() function to obtain the file nameDetailed explanation of the definition and usage of the php parse_url() functionThe above is the detailed content of Example explanation of using php pathinfo(), parse_url(), basename() functions to parse URLs. For more information, please follow other related articles on the PHP Chinese website!