Home > Backend Development > PHP Tutorial > Several common functions of Url, common functions of Url_PHP tutorial

Several common functions of Url, common functions of Url_PHP tutorial

WBOY
Release: 2016-07-12 09:06:50
Original
834 people have browsed it

Several common functions of Url, common functions of Url

parse_url()

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

This function is not used to verify the validity of the given URL, but to break it down into the parts listed below. Incomplete URLs are also accepted and parse_url() will try to parse them as correctly as possible.

    <span>$_url</span> = "http://www.baidu.com/web?id=15&page=5"<span>;
    $_par = pares_url($_url);
    </span><span>var_dump</span>($_par);<br /><br />输出结果:
Copy after login
<span>array</span>(4<span>) {
  [</span>"scheme"]=>
  <span>string</span>(4) "http"<span>
  [</span>"host"]=>
  <span>string</span>(13) "www.baidu.com"<span>
  [</span>"path"]=>
  <span>string</span>(4) "/web"<span>
  [</span>"query"]=>
  <span>string</span>(12) "id=15&page=5"<span>
}</span>
Copy after login
Copy after login

parse_str()

Parse the string into multiple variables

    <span>parse_str</span>(<span>$_par</span>['query'],<span>$_query</span><span>);
    </span><span>var_dump</span>(<span>$_query</span><span>);

输出结果:
</span><span>array</span>(2<span>) {
  [</span>"id"]=>
  <span>string</span>(2) "15"<span>
  [</span>"page"]=>
  <span>string</span>(1) "5"<span>
}</span>
Copy after login

http_bulid_query()

Generate a URL-encoded request string using the given associative (or subscript) array.

    <span>unset</span>(<span>$_query</span>['page']);  <span>//</span><span>清空page</span>
    <span>var_dump</span>(<span>http_build_query</span>(<span>$_query</span><span>));

输出:


</span><span>string</span>(5) "id=15"
Copy after login

Used to parse, split, and reorganize URL strings.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1063516.htmlTechArticleUrl several commonly used functions, Url common function parse_url() This function parses a URL and returns an associative array, Contains various components that appear in the URL. This function is not used to verify...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template