PHP uses the functions pathinfo(), parse_url() and basename() to parse URLs

墨辰丷
Release: 2023-03-28 13:46:02
Original
1622 people have browsed it

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);
?>
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 the parse_url() function to parse

<?
 $test = parse_url("http://localhost/index.php?name=tank&sex=1#top");
 print_r($test);
?>
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

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

The results are as follows

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

The above is the entire content of this article, I hope it will be helpful to everyone’s study .


Related recommendations:

PHP7 multi-threading tutorial

## phpRealize reading and saving base64 encoded image content
##Ajax

php

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!

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!