我有一串URL格式。
就是这个。 “http://test.com/foo/bar/detail.php?key=KEY&other=x”
我需要从URL中提取“KEY”。
与此类似。
$foo = $_GET['key'];
但我所拥有的是一串URL格式 我如何提取KEY这个字符串?
答案 0 :(得分:0)
您可以使用parse_url()
:http://php.net/manual/en/function.parse-url.php和parse-str
http://php.net/manual/en/function.parse-str.php
$string = "http://test.com/foo/bar/detail.php?key=KEY&other=x";
$query = parse_url($url, PHP_URL_QUERY);
$variable = parse_str($query, $output);
echo $output['key'];