URL GET vars to PHP Array

0 min read 120 words

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:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags