URL GET vars to PHP Array

Sometimes you will need to retrieve the GET variables passed into the current page URI or you will have a URL string to work from which contains certain GET variables, the below method helps a lot to convert them into an array which you can easily manipulate later.

$url = $_SERVER["REQUEST_URI"];
parse_str(parse_url($url, PHP_URL_QUERY), $array);

$array is now an array of all the GET variables in the URL.

Alternatively you can pass a URI string in place of the $_SERVER[“REQUEST_URI”] by replacing the $url variable with something else.

No need for an example on that one, as I’m sure if you’re already reading this post then you will know what to do.

If all else fails then leave a comment below..

Tags:
0 0 vote
Article Rating
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
vps tw
vps tw
6 years ago

It’s actually a nice and helpful piece of information.
I’m satisfied that you shared this helpful information with us.
Please stay us informed like this. Thank you for sharing.