Home >php教程 >php手册 >php中parse_url()函数用法介绍

php中parse_url()函数用法介绍

WBOY
WBOYOriginal
2016-06-13 10:14:22842browse

本文章介绍了关于php中parse_url()函数用法介绍,有需要使用parse_url()函数的朋友可以参考一下本文章。

PHP中一个好用的函数parse_url,特别方便用来做信息抓取的分析,举例子如下:

 代码如下 复制代码

$url = "http://www.bKjia.c0m/aaaa/";$parts = parse_url($url);

输出:
Array
(
    [scheme] => http
    [host] => www.bKjia.c0m
    [path] => /aaaa/
)

又如:

 代码如下 复制代码

输出:
Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)

可以看到,可以很容易分解出一个URL的各个部,那如果要拿指定的部分出来的话也很容易,如

echo parse_url($url, PHP_URL_PATH);
就是在第二个参数中,设定如下的参数:
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.

 

Statement:
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