john
john

Reputation: 1273

how to grab part of query string in url with $_SERVER['QUERY_STRING']

I have a couple of url strings like below:

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

In case the url is" 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

Upvotes: 1

Views: 280

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78994

It will be the first in the $_GET superglobal, so:

$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";

Upvotes: 1

Related Questions