Home >Backend Development >PHP Tutorial >A useful function in PHP parse_url_PHP tutorial

A useful function in PHP parse_url_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:55:50869browse

A useful function in PHP, parse_url, is particularly convenient for analysis of information capture. An example is as follows:
$url = "http://www.electrictoolbox.com/php-extract-domain- from-full-url/";
$parts = parse_url($url);
Output:
Array
(
[scheme] => http
[host] = > www.electrictoolbox.com
[path] => /php-extract-domain-from-full-url/
)

Another example:

< ?php
$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH);
?>

Output:
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. 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364336.htmlTechArticleA useful function parse_url in PHP, which is particularly convenient for analysis of information capture. An example is as follows: $url = http://www.electrictoolbox.com/php-extract-domain-from-full-url/; $parts = pa...
Statement:
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