Home  >  Article  >  Backend Development  >  php uses the functions pathinfo(), parse_url() and basename() to parse the URL_php instance

php uses the functions pathinfo(), parse_url() and basename() to parse the URL_php instance

WBOY
WBOYOriginal
2016-12-05 13:28:271223browse

This article mainly introduces the example code of using PHP functions pathinfo(), parse_url() and basename() to parse URLs. Not much to say below, let’s look at the code directly

The example code is as follows:

1. Use pathinfo to parse URL

<&#63;
 $test = pathinfo("http://localhost/index.php");
 print_r($test);
&#63;>

The results are as follows

Array
(
 [dirname] => http://localhost //url的路径
 [basename] => index.php //完整文件名
 [extension] => php //文件名后缀
 [filename] => index //文件名
)

2. Use parse_url() function to parse

<&#63;
 $test = parse_url("http://localhost/index.php&#63;name=tank&sex=1#top");
 print_r($test);
&#63;>

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

<&#63;
 $test = basename("http://localhost/index.php&#63;name=tank&sex=1#top");
 echo $test;
&#63;>

The results are as follows

index.php&#63;name=tank&sex=1#top

Summary

The above is the entire content of this article. I hope the content of this article can bring some help to everyone's study or work. If you have any questions, you can leave a message to communicate.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn