Home > Backend Development > PHP Tutorial > Usage of function parse_url in PHP

Usage of function parse_url in PHP

小云云
Release: 2023-03-20 12:10:01
Original
25516 people have browsed it

This article mainly shares with you a useful function parse_url in PHP, which is especially convenient for analysis of information capture. I hope it can help everyone.

Recommended Manual:php Complete Self-Study Manual

Code

$url = "http://www.electrictoolbox.com/php-extract-domain-from-full-url/"; 
$parts = parse_url($url);
Copy after login

Result

Array ( 
[scheme] => http 
[host] => www.electrictoolbox.com 
[path] => /php-extract-domain-from-full-url/ 
)
Copy after login

Code

<?php $url = &#39;http://username:password@hostname/path?arg=value#anchor&#39;; 
print_r(parse_url($url)); 
echo parse_url($url, PHP_URL_PATH); 
?>
Copy after login

Result

Array ( 
[scheme] => http 
[host] => hostname 
[user] => username 
[pass] => password 
[path] => /path 
[query] => arg=value 
[fragment] => anchor 
)
Copy after login

As you can see, it is easy to decompose the various parts of a URL, and it is also easy to extract the specified parts, such as

echo parse_url($url, PHP_URL_PATH);
Copy after login

is to set the following parameters in the second parameter:

PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT.
Copy after login
Recommended related articles:
1.Use php pathinfo (), parse_url(), basename() function parsing URL examples
2.Introduction to php using parse_url and parse_str to parse URLs
Related video recommendations:
1.Dugu Jiujian (4)_PHP video tutorial

Other recommendations:

How to parse parse_url parameter into array parse_str ​ ​
10 recommended courses on parse_url()
The difference between the php parse_str() function and the parse_url() function in parsing URLs

The above is the detailed content of Usage of function parse_url in PHP. 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