PHP: Removing specific parameters from querystring.
Posted on 2009-04-15
I want to create a set of links that remove specific parameters from a querysting.
If Querystring = ?A=1&B=2&C=3&D=4
I want a link to Remove "A" and return ?B=2&C=3&D=4.
I then also want some links to remove "A" and "B" and return ?C=3&D=4.
Additionally, i then may need a link to remove "A" and "B" and add "E=5"
I'm not sure of the best way to do this.
Currently i've done this by using str_replace() for each parameter i want a link to remove, however, doing this for all the possible parameters is resulting in over 150 lines of code.
It's occured to me to use explode() to create a master array of the querysting and then creating a new array with the specifically removed parameter(S) using implode("&",) function.
However, i'm not having much luck.