A useful function in PHP: parse_url

Source: Internet
Author: User
A useful function in PHP, parse_url, is particularly convenient for information capture analysis. For example:
$ 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));

EchoParse_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, each part of a URL can be easily decomposed. It is also easy to obtain the specified part, for 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.