$ url ='http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+c';
如果是网址,我可以通过hl
得到$_GET['hl']
的价值。但是如何从$ url字符串中检索相同内容。
感谢。
答案 0 :(得分:6)
以下是步骤:
$url = 'http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+c';
print "<pre>";
print $url;
$url_parsed = parse_url($url);
print_r($url_parsed);
parse_str($url_parsed['query'], $url_parts);
print_r($url_parts);
print "</pre>";
生成此输出:
http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+cArray
(
[scheme] => http
[host] => www.domain.com
[path] => /file.php
[query] => dir=r&hl=100,200&ord=3&key=a+b+c
)
Array
(
[dir] => r
[hl] => 100,200
[ord] => 3
[key] => a b c
)
因此,获取所需 h1
值的步骤如下:
$url = 'http://www.domain.com/file.php?dir=r&hl=100,200&ord=3&key=a+b+c';
$url_parsed = parse_url($url);
parse_str($url_parsed['query'], $url_parts);
print $url_parts['h1'];
答案 1 :(得分:4)