Replacing a URL variable...
Posted: Sat Jan 21, 2006 11:18 pm
I've got a class that i've created that basically allows me to create a url or use the current one and add or take out variables.
EX: sub("var1")
The idea that i am having is that there should be a better way to do so than i am using. is there a way to find the variable in a string and replace it with nothing? the way i'm doing it is just to search either ?var1= or &var1= and finding the next & or end of string and replacing that portion with ''. Is there a preg_replace way of doing this?
EX: sub("var1")
Code: Select all
http://www.site.com/index.php?var1=hello&var2=world => http://www.site.com/index.php?var2=world