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
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Thu Sep 01, 2005 3:33 pm
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..
bokehman
Forum Regular
Posts: 509 Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)
Post
by bokehman » Thu Sep 01, 2005 4:13 pm
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--;
}
?>
Last edited by
bokehman on Fri Sep 02, 2005 2:24 am, edited 3 times in total.
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Thu Sep 01, 2005 11:20 pm
you could look at the query string / http request in the server superglobal
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Fri Sep 02, 2005 5:10 am
You could also
strstr () it and use
split () on the &. Might be easier if you have unknown amount of &-vars?