Re: Regex in PHP

From: Date: Thu, 05 Jun 2008 03:43:24 +0000
Subject: Re: Regex in PHP
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.general 
Request: Send a blank email to php-general+get-275039@lists.php.net to get a copy of this message
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

« previous php.general (#275039) next »