Return the $_GET array as a string?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LonelyProgrammer
Forum Contributor
Posts: 108
Joined: Sun Oct 12, 2003 7:10 am

Return the $_GET array as a string?

Post by LonelyProgrammer »

Is there any way to convert the $_GET array back into its original query string?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Maybe:

Code: Select all

echo $_SERVER['QUERY_STRING'];
is what you're looking for.

-Nay
LonelyProgrammer
Forum Contributor
Posts: 108
Joined: Sun Oct 12, 2003 7:10 am

Post by LonelyProgrammer »

*smack forehead for forgetting to check documentation*

But what if I want the string passed using the $_POST method?
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Code: Select all

<?php

$string = '';

foreach($_POST as $key => $value) {
   if(empty($string)) {
      $string .= $key . "=" . $value;
   } else {
      $string .= "&" . $key . "=" . $value
   }
}

?>
I'm not sure if there's any other way though.

-Nay
Post Reply