How to return $ _GET variable names in php url

I want to save the name of all $ _GET variables in the url, but I'm not sure where to start, or would end it.

For instance:

if I have:

url: test.com/forums.php?topic=blog&discussion_id=12

Can I use php to get the name, i.e. "topic" and "Discussion_id" from $ _GET variables, and can I then store the values: "topic" and "discussion_id" in an array?

+5
source share
5 answers

You can get this by calling array_keysin $_GET:

$getVars = array_keys($_GET);
+13
source

If this is not about the current URL, but only about some url string that you want to extract from this parameter:

parse_str(parse_url($url, PHP_URL_QUERY), $params);

will populate $ params with:

[topic] => blog
[discussion_id] => 12
+5

URL GET. $_POST .

<?php
foreach ( $_GET as $key => $value ) 
{
        //other code go here
    echo 'Index : ' . $key . ' & Value : ' . $value;
    echo '<br/>';
}
?>
+3

$_ GET - php-. foreach:

foreach ($_GET as $k => $v)
  echo ($k . '=' . $v);
+1

:

print_r($_GET);

Retrieve the elements as you would with any other array.

0
source

All Articles