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:///...)。其它任何协议都不能这样。
参见
parse_str() - Parses the string into variables
parse_str() 函数把查询字符串解析到变量中
<?php
parse_str("id=23&name=John%20Adams");
echo $id."<br />";
echo $name;
?>
输出:
23
John Adams