parse_url()

来源:互联网 发布:阿里云 云监控 编辑:程序博客网 时间:2024/04/29 20:21
Example #1 parse_url() 例子
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
?>
以上例程会输出:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)


注释

Note:
本函数不能用于相对 URL。
Note:
parse_url() 是专门用来解析 URL 而不是 URI 的。不过为遵从 PHP 向后兼容的需要有个例外,对 file:// 协议允许三个斜线(file:///...)。其它任何协议都不能这样。


参见

pathinfo() - 返回文件路径的信息
parse_str() - Parses the string into variables
dirname() - 返回路径中的目录部分
basename() - 返回路径中的文件名部分

parse_str() 函数把查询字符串解析到变量中
<?phpparse_str("id=23&name=John%20Adams");echo $id."<br />";echo $name;?>

输出:

23John Adams