NYCPHP Meetup

NYPHP.org

Regular Expressions + URL

Jerry Kapron jkapron at NewAgeWeb.com
Sun Jan 26 03:03:23 EST 2003


I'm trying to get rid of a specific name=value pair from a URL (query
string).
In this case it's baked=any_value. Note that it may appear in different
context and removing additional preceding or trailing characters (& and/or
?) may be required.  Here are the 4 different cases:
...?baked=any_value&...   (as the first but not only name=value pair)
...?baked=any_value    (as the only name=value pair)
...&baked=any_value&...   (between other name=value pairs)
...&baked=any_value   (as the last of many name=value pairs)

I solved this with these 3 lines of code:

   $uri = ereg_replace('&?baked=[^&]*','',$uri);     // ? == {,1}
   $uri = ereg_replace('\\?&','?',$uri);
   $uri = ereg_replace('\\?$','',$uri);

I was just wondering wether there is a shorter way (one preg_replace()
perhaps?).

thanks,
Jerry


--
42.7% of all statistics are made up on the spot. -




More information about the talk mailing list