[nycphp-talk] Regular Expressions + URL
The Rain Maker
rainman at deroo.net
Sun Jan 26 09:07:46 EST 2003
On Sunday, Jan 26, 2003, at 03:01 America/New_York, Jerry Kapron wrote:
> I'm trying to get rid of a specific name=value pair from a URL (query
> string).
> 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
---
Raymond DeRoo -- Senior Partner
Support Services -- (203) 952-3900
www.supserv.com -- rderoo at supserv.com
More information about the talk
mailing list