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

WBOY
Release: 2023-03-03 07:28:01
Original
1222 people have browsed it

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;>
Copy after login

The results are as follows

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

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;>
Copy after login

The results are as follows

Array
(
 [scheme] => http //使用什么协议
 [host] => localhost //主机名
 [path] => /index.php //路径
 [query] => name=tank&sex=1 // 所传的参数
 [fragment] => top //后面根的锚点
)
Copy after login

3. Use basename() to parse

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

The results are as follows

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

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!