PHP Functions in detail: Parse_url ()

Source: Internet
Author: User
The Parse_url () function resolves the URL and returns its constituent parts. Its usage is as follows: Array parse_url (string URL) This function returns an associative array containing the various components of an existing URL. If one of these is missing, an array entry is not created for this component. The components are:
    • scheme– such as HTTP
    • Host
    • Port
    • User
    • Pass
    • Path
    • query– in question marks? After
    • fragment– after the hash symbol #
This function does not imply that the given URL is legal, it simply separates the parts of the list above. Parse_url () can accept an incomplete URL and try to parse it correctly. This function has no effect on the URL of the relative path.
    1. $url = "http://www.nowamagic.net/welcome/";
    2. $parts = Parse_url ($url);

    3. Print_r ($parts);
    4. ?>
Copy Code
The results of the program run as follows:
    1. Array ([scheme] + http [host] = www.nowamagic.net [path] =/welcome/)

    2. $url = ' Http://username:password@hostname/path?arg=value#anchor ';
    3. Print_r (Parse_url ($url));
    4. Echo Parse_url ($url, Php_url_path);
    5. ?>
Copy Code
Program output:
    1. Array
    2. (
    3. [Scheme] = http
    4. [Host] = hostname
    5. [User] = Username
    6. [Pass] = password
    7. [Path] =/path
    8. [Query] = Arg=value
    9. [Fragment] = Anchor
    10. )
    11. /path
Copy Code
As you can see, it's easy to break out the various parts of a URL, which is easy if you want to take the specified part out, such as:
    1. Echo Parse_url ($url, Php_url_path);
Copy Code
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.