Re: preg_replace() question
| From: | Robert Cummings | Date: | Wed, 18 Mar 2009 15:02:12 +0000 |
| Subject: | Re: preg_replace() question | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-290240@lists.php.net to get a copy of this message | ||
On Wed, 2009-03-18 at 22:55 +0800, Virgilio Quilario wrote:
> > 1. What is the overhead on preg_replace?
>
> it really depends on your operation. when you think it can be done
> using str* functions then go for it as they are much faster than preg*
> functions.
>
> > 2. Is there a better way to strip spaces and non alpha numerical
> > characters from text strings? I suspect not... maybe the Shadow does ???
>
> if those characters are in the middle, preg_replace is the right function.
Unless you know how many, it's probably the right function even if
they're at the front or end. preg_replace() is almost certainly faster
(in this particular case) than making two function calls.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP