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?
You can get this by calling array_keysin $_GET:
array_keys
$_GET
$getVars = array_keys($_GET);
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
URL GET. $_POST .
<?php foreach ( $_GET as $key => $value ) { //other code go here echo 'Index : ' . $key . ' & Value : ' . $value; echo '<br/>'; } ?>
$_ GET - php-. foreach:
foreach ($_GET as $k => $v) echo ($k . '=' . $v);
:
print_r($_GET);
Retrieve the elements as you would with any other array.