RE: [PHP] removing text from a string
| From: | Boyd, Todd M. | Date: | Thu, 06 Nov 2008 16:07:44 +0000 |
| Subject: | RE: [PHP] removing text from a string | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-283000@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jim Lucas [mailto:lists@cmsws.com]
> Sent: Thursday, November 06, 2008 9:58 AM
> To: tgol@kinetix.gr
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] removing text from a string
>
> Thodoris wrote:
> >
> >> Ashley Sheridan a écrit :
> >>
> >>> Thats a lot of code when a couple of lines and a regex will do ;)
> >>
> >> Maybe because the use of the regex is pointless here. A bazooka to
> >> kill the fly ? :)
> >>
> >
> > I couldn't agree more. Not to mention that they are probably slower.
> >
> > PS Don't get me wrong I like perl and pcre but it is pointless here.
> >
>
> Personal choice, and yes my testing has proven that a regex is faster
> then the multiple function calls or if conditions needed to accomplish
> the same
> thing.
Yeah, I think people under-estimate the performance of (SIMPLE) Regular Expressions for text
manipulation and searching. As long as you don't have like 15 nested groups and callbacks and
optional chars/groups out the wazoo in your PCRE pattern, it will be very quick: it was designed
with efficiency and speed in mind.
I feel it's also worth mentioning that it may be worthwhile to lean towards RegEx functions for
text searching/manipulation so that there is a consistency between methods throughout your code. 15
regex patterns may be better than intermingling xtrim(), strstr(), stripos(), str_replace(), etc...
and are probably more easily-readable than scanning 15 10-line algorithms to discern their purpose.
Just a thought.
Todd Boyd
Web Programmer
RegEx Fan (but not Fanatic)