Take all $ _GET and add the end of the url?

I have a bunch of date = desc sorting methods, etc. etc., and they are sent via $_GET . I want to take all the $_GET variables ( $_GET['anythingatall'] ) and convert them from $_GET['variable]=blah to &variable=blah

Is there an easy way to do this?

+4
source share
4 answers

You are interested in $_SERVER['QUERY_STRING'] , I think. This will contain everything that passed in $_GET , but in the desired format.

+11
source

This may work for you.

  $string = http_build_query($_GET, null, '&') 

Alex's solution should work too, and admittedly a cleaner one. If you want to create a query string from any other array using http_build_query, you should work fine.

+7
source

If all you have to do is transfer the existing query string (which is available in $_GET ), you can use $_SERVER['QUERY_STRING'] , which will be exactly what you are looking for, the query string representation of the $_GET array (if you did not change it)

See the PHP documentation at the $_SERVER Supergalon .

+2
source

Source: https://habr.com/ru/post/1334409/


All Articles