An example is as follows:
Copy code The code is as follows:
$url = "http://www.electrictoolbox.com/ php-extract-domain-from-full-url/";
$parts = parse_url($url);
Output:
Copy Code The code is as follows:
Array
(
[scheme] => http
[host] => www.electrictoolbox.com
[path] => /php-extract-domain-from-full-url/
)
Another example:
Copy code The code is as follows:
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>
Output:
Copy code The code is as follows:
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);
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.
http://www.bkjia.com/PHPjc/320613.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320613.htmlTechArticleAn example is as follows: Copy the code as follows: $url = "http://www.electrictoolbox.com/php -extract-domain-from-full-url/"; $parts = parse_url($url); Output: Copy the code as follows: A...