[英]how to grab part of query string in url with $_SERVER['QUERY_STRING']
I have a couple of url strings like below:我有几个 url 字符串,如下所示:
admin.php?filter_status=New
admin.php?filter_status=New¤tpage=2
and和
admin.php?entry_search=Ready
admin.php?entry_search=Ready¤tpage=3
How can i grab always the value between ?
我怎样才能始终抓住 之间的价值?
and &
?和&
?
So: entry_search=Ready
or filter_status=New
所以: entry_search=Ready
或entry_search=Ready
filter_status=New
In case the url is" admin.php?entry_search=Ready¤tpage=3
;如果网址是“ admin.php?entry_search=Ready¤tpage=3
;
$_SERVER['QUERY_STRING']
gives me entry_search=Ready¤tpage=3
and it should always give me only entry_search=Ready
$_SERVER['QUERY_STRING']
给我entry_search=Ready¤tpage=3
并且它应该总是只给我entry_search=Ready
It will be the first in the $_GET
superglobal, so:它将是$_GET
超全局变量中的第一个,因此:
$val = reset($_GET);
$key = key($_GET);
To use the query string:要使用查询字符串:
parse_str($_SERVER['QUERY_STRING'], $array);
$val = reset($array);
$key = key($array);
If you really need a string then:如果你真的需要一个字符串,那么:
$result = "$key=$val";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.