Page 1 of 1
Unnamed GET vars
Posted: Thu Sep 01, 2005 3:33 pm
by onion2k
Is there a better way to get at unnamed variables in a GET request (eg
http://www.domain.com/?1234&5678) than:
Code: Select all
$keys = array_keys($_GET);
$var1 = $keys[0];
$var2 = $keys[1];
That seems a little messy to me but I'm having a mental block..
Posted: Thu Sep 01, 2005 4:13 pm
by bokehman
Edited: Hmm! That didn't work but this does.
Code: Select all
<?php
$i = 1; // Save variables
foreach($_GET as $k => $v){
if(!empty($k)){
$var{$i} = $k;
$i++;
}
}
while($i > 0){ // Test: Print variables
print $var{$i}."<br>\n";
$i--;
}
?>
Posted: Thu Sep 01, 2005 11:20 pm
by josh
you could look at the query string / http request in the server superglobal
Posted: Fri Sep 02, 2005 5:10 am
by JAM
You could also
strstr() it and use
split() on the &. Might be easier if you have unknown amount of &-vars?