Home >Backend Development >PHP Tutorial >Usage of function parse_url in PHP
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);
Result
Array ( [scheme] => http [host] => www.electrictoolbox.com [path] => /php-extract-domain-from-full-url/ )
Code
<?php $url = 'http://username:password@hostname/path?arg=value#anchor'; print_r(parse_url($url)); echo parse_url($url, PHP_URL_PATH); ?>
Result
Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor )
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);
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.
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!