Page 1 of 1

Replacing a URL variable...

Posted: Sat Jan 21, 2006 11:18 pm
by Zoram
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")

Code: Select all

http://www.site.com/index.php?var1=hello&var2=world => http://www.site.com/index.php?var2=world
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?

Posted: Sat Jan 21, 2006 11:21 pm
by hawleyjr
Check out $_SERVER['argv']

This will give you an array of arguments.

Code: Select all

echo '<HR><PRE>'; print_r($_SERVER); echo '</PRE>';

Posted: Sat Jan 21, 2006 11:25 pm
by Zoram
You may have just destroyed an hour of programming with that statement... thanks ;)

Posted: Sat Jan 21, 2006 11:27 pm
by hawleyjr
LMAO, I can delete the post if you want your hour back :lol: :lol: :lol:

j/k