Re: [PHP] Regex in PHP
- Date: Wed, 04 Jun 2008 23:43:24 -0400
- From: Robert Cummings <robert@xxxxxxxxxxxxx>
- Subject: Re: [PHP] Regex in PHP
On Wed, 2008-06-04 at 23:20 -0400, Nathan Nobbe wrote:
>
> i repeated your test using the time program and splitting the script into 2,
> one for each strpos and stripos, to find similar results. imo, there is no
> need for 2 comparisons for case-insensitive searches, because both arguments
> can be converted to a single case prior to the search. obviously, there is
> a small amount of overhead there the case-sensitive search is unencumbered
> by. i guess i never sat down and thought about how that algorithm would
> work (case-sensitive) =/.
>
> thanks for the tips rob. sorry to bother you richard.
You would do two comparisons... why incur the overhead of a conversion
if one is not necessary. First you do case sensitive match, if that
fails then you try the alternative version comparison. It is inefficient
to perform 2 conversions and a single comparison in contrast. Similarly,
it's very inefficient to convert two entire strings then perform a
comparison. If the first characters differ then conversion of the rest
of the strings was pointless. This is basic algorithms in computer
science.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php