Home > Article > Backend Development > Introduction to the usage of parse_url() function in php
This article introduces the usage of parse_url() function in PHP. Friends who need to use parse_url() function can refer to this article.
A useful function parse_url in PHP is particularly convenient for analysis of information capture. An example is as follows:
$url = "http://www.daimajiayuan.com/course/"; $parts = parse_url($url);
Code output:
Array ( [scheme] => http [host] => www.daimajiayuan.com [path] => /course )
Another example:
<?php $url = 'http://username:password@hostname/path?arg=value#anchor'; print_r(parse_url($url)); echo parse_url($url, PHP_URL_PATH); ?>
Code output:
Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor )
As you can see, it can be easily decomposed into a For each part of the URL, it is easy to extract the specified part, such as and another example:
echo parse_url($url, PHP_URL_PATH);
In the second parameter, set the following parameters:
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.