Expanding on my original question here: I would now like to remove more than 1 variable from the querystring.
For example, I want to remove the variables bar1
& bar2
from the querystring. I have tried the following code:
echo parseQueryString("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],"bar2","bar1");
But this doesn't remove both variables, only bar2
.
Any help appreciated.
Thank you,
Matt
You'll be wanting something like
Alternatively, since I'm assuming parseQueryString is a function you defined, you can change it so it accepts an array argument and loops over the array.
I have created a new function which works with multiple parameters.
I don't think the
parseQueryString
function will work for query strings with array components such as&bar[]=5&bar[]=12
etc. I think all but one would be dropped from the result.I would use
parse_str($_SERVER["QUERY_STRING"], $array);
to take apart the query stringunset($array["bar1"]);
to remove the unwanted variableshttp_build_query($array);
to glue the query string back together