[nycphp-talk] Regular Expressions + URL
Jerry Kapron
jkapron at NewAgeWeb.com
Sun Jan 26 12:38:56 EST 2003
>On Sunday, Jan 26, 2003, at 03:01 Jerry Kapron wrote:
>> 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?).
>
>Yup, there sure is...
>
>$uri = preg_replace("/[?&]baked=[^&]+/", '', $uri);
>
>And you are good to go.
>
>r
Ray,
This wouldn't work. Note that if baked=any_value was the first of many
name=value pairs in a query string, your preg_replace() would remove the '?'
(that's not good).
Jerry
More information about the talk
mailing list