Replacing a URL variable...

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Replacing a URL variable...

Post 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?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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>';
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post by Zoram »

You may have just destroyed an hour of programming with that statement... thanks ;)
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

LMAO, I can delete the post if you want your hour back :lol: :lol: :lol:

j/k
Post Reply