tags:

views:

80

answers:

4

if i have a link like this

http://www.website.com/index.php?a=1&b=2&c=3&d=4

how can i print out all the parameters and its values without doing print $_POST['a'];

thanks

+2  A: 
foreach($_GET as $key => $value){
  echo $key . " : " . $value . "<br />\r\n";
}
echo
+1  A: 

The parameters are in the URL, so are available in $_GET ; and you can loop over that array using foreach :

foreach ($_GET as $name => $value) {
    echo $name . ' : ' . $value . '<br />';
}
Pascal MARTIN
Link to `$_GET` docu: http://php.net/manual/en/reserved.variables.get.php
Felix Kling
+4  A: 

I use

print_r($_GET);
jab
+1  A: 

You can also use parse_url() and parse_str():

$url = 'http://www.example.com/index.php?a=1&amp;b=2&amp;c=3&amp;d=some%20string';
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query);
parse_str($query, $arr);

echo $query;  // a=1&b=2&c=3&d=some%20string

echo $a;  // 1
echo $b;  // 2
echo $c;  // 3
echo $d;  // some string

foreach ($arr as $key => $val) {
    echo $key . ' => ' . $val . ', ';  // a => 1, b => 2, c => 3, d => 4
}
GZipp