Url-related common functions

Source: Internet
Author: User
Url: several common functions: parse_url () this function parses a URL and returns an associated array, including the various components in the URL. This function is not used to verify the validity of a given URL, but is used to separate it into the parts listed below. Incomplete URLs are also accepted, and parse_url () tries to parse them correctly as much as possible. & Nbsp; $ _ urlwww.baidu.com

Parse_url ()

This function parses a URL and returns an associated array, which contains various components in the URL.

This function is not used to verify the validity of a given URL, but is used to separate it into the parts listed below. Incomplete URLs are also accepted,Parse_url ()Will try to correctly parse it as much as possible.

$ _ Url = "http://www.baidu.com/web? Id = 15 & page = 5 "; $ _ par = pares_url ($ _ url); var_dump ($ _ par );

Output result:

array(4) {  ["scheme"]=>  string(4) "http"  ["host"]=>  string(13) "www.baidu.com"  ["path"]=>  string(4) "/web"  ["query"]=>  string(12) "id=15&page=5"}

 

Parse_str ()

Parses a string into multiple variables.

Parse_str ($ _ par ['query'], $ _ query); var_dump ($ _ query); output result: array (2) {["id"] => string (2) "15" ["page"] => string (1) "5 "}

Http_bustm_query ()

Generate a URL-encode request string using the given correlated (or subscript) array.

Unset ($ _ query ['Page']); // clear page var_dump (http_build_query ($ _ query); output: string (5) "id = 15"

It is used to parse, split, and reorganize URL strings.

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.