parse_url resolves the URL and returns its components

Source: Internet
Author: User
Parse_url

(PHP 4, PHP 5)

parse_url-resolves the URL, returning its component description array parse_url (string $url)

This function resolves a URL and returns an associative array containing the various components that appear in the URL.

This function is not used to verify the legality of a given URL, but to decompose it into the sections listed below. An incomplete URL is also accepted, andParse_url () tries to parse it as correctly as possible. Parameters

Url

The URL return value to resolve

For severely unqualified URLs,parse_url () may return FALSE and emit e_warning. Otherwise, an associative array is returned with a component (at least one): scheme-such as HTTP host port user Pass path query-at the question mark? After fragment-The example after the hash symbol #

example 2369. Parse_url () example <?php
$url = ' Http://username:password@hostname/path?arg=value#anchor ';

Print_r (Parse_url ($url));
?>

The example above will output:

Array
(
[Scheme] => http
[Host] => hostname
[User] => username
[Pass] => password
[Path] =>/path
[Query] => arg=value
[Fragment] => anchor
)


Notes

Note: This function cannot be used for relative URLs.

Note: Parse_url () is specifically used to resolve URLs rather than URIs. However, there is an exception to the need to comply with PHP's backward compatibility, which allows three slashes (file:///...) for the file://protocol. )。 No other agreement can do that.

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.