简体   繁体   English

如何使用 $_SERVER['QUERY_STRING'] 在 url 中获取部分查询字符串

[英]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&currentpage=2

and

admin.php?entry_search=Ready
admin.php?entry_search=Ready&currentpage=3

How can i grab always the value between ?我怎样才能始终抓住 之间的价值? and & ?& ?

So: entry_search=Ready or filter_status=New所以: entry_search=Readyentry_search=Ready filter_status=New

In case the url is" admin.php?entry_search=Ready&currentpage=3 ;如果网址是“ admin.php?entry_search=Ready&currentpage=3 ;

$_SERVER['QUERY_STRING'] gives me entry_search=Ready&currentpage=3 and it should always give me only entry_search=Ready $_SERVER['QUERY_STRING']给我entry_search=Ready&currentpage=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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM