I want to save the name of all the $_GET variables in a url, but im not sure where to start, or finish for that matter.
For example:
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 the $_GET variables and can i then store the values: "topic" and "discussion_id" in an array?
You can get this by calling array_keys
on $_GET
:
$getVars = array_keys($_GET);
If this isn't about the current URL, but just some $url string you want to extract the parameters from then:
parse_str(parse_url($url, PHP_URL_QUERY), $params);
will populate $params with:
[topic] => blog
[discussion_id] => 12
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With