Page 1 of 1
querystring remove duplicate
Posted: Wed Mar 14, 2007 1:37 pm
by louie35
This is doing my **** in.
Does anybody knows a clean solution for removing duplicated string + values from a querystring?
ex. page.php?1=1&2=2&1=3 to page.php?2=2&1=3
Posted: Wed Mar 14, 2007 2:04 pm
by feyd
parse_str() combined with something else, maybe?
PHP will automatically handle the smashing down of the information if you're worried about that.
Posted: Wed Mar 14, 2007 2:33 pm
by louie35
tried that, didn't work as it was supposed to or I was missing something.
Posted: Wed Mar 14, 2007 3:53 pm
by John Cartwright
I believe apache will only process the last instance of a variable in the query string..
as feyd mentioned, if your physically manipulating the string then parse_str(), and perhaps a funky combination of array_unique(), and array_keys() should work.
Posted: Thu Mar 15, 2007 3:40 am
by louie35
all i needed was a clear head. I came up with this:
Code: Select all
$a = explode("&", $_SERVER['QUERY_STRING']);
$query = array_unique($a);
foreach($query as $q_name){
$query_s .= $q_name."&";
}
$query_s = rtrim($query_s,"&");//remove last trailing &
if you know a better solution let me know.
Posted: Thu Mar 15, 2007 5:07 am
by stereofrog
This can be written shorter with implode().