As we all know, the functions pathinfo(), parse_url() and basename() in PHP are all functions for parsing URLs, but there are some differences. Some examples are listed below. It is easier to understand these three through examples. Friends in need can refer to the methods and techniques for using functions. Friends who are interested can learn together below.
This article mainly introduces the example code of php using the functions pathinfo()
, parse_url()
and basename()
, as follows Without further ado, let’s look directly at the code
The example code is as follows:
1. Use pathinfo to parse the URL
<? $test = pathinfo("http://localhost/index.php"); print_r($test); ?>
The results are as follows
Array ( [dirname] => http://localhost //url的路径 [basename] => index.php //完整文件名 [extension] => php //文件名后缀 [filename] => index //文件名 )
2. Use the 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 //使用什么协议 [host] => localhost //主机名 [path] => /index.php //路径 [query] => name=tank&sex=1 // 所传的参数 [fragment] => top //后面根的锚点 )
##3. Use basename() to parse
<? $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
## phpRealize reading and saving base64 encoded image content
##Ajax
Realize three-level linkage of product classification
The above is the detailed content of PHP uses the functions pathinfo(), parse_url() and basename() to parse URLs. For more information, please follow other related articles on the PHP Chinese website!