Re: Regex in PHP

From: Date: Wed, 04 Jun 2008 16:56:12 +0000
Subject: Re: Regex in PHP
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-275021@lists.php.net to get a copy of this message
On Wed, Jun 4, 2008 at 10:26 AM, Robert Cummings <robert@interjinn.com> wrote: > Nope, case insensitive is slower since you must make two tests for > characters having a lower and upper case version. With case sensitive > comparisons you only need to make a single comparison. a quick test shows stripos beating strpos. <?php $str = 'asSAFAASFDADSfasfjhalskfjhlaseAERQWERQWER;.dafasjhflasfjd'; $search = 'fdasASDFAafdas'; $start = microtime(); strpos($str, $search); $end = microtime(); $r1 = $end - $start; $start = microtime(); stripos($str, $search); $end2 = microtime(); $r2 = $end2 - $start; echo "strpos: $r1\n"; echo "stripos: $r2\n"; if($r2 < $r1) { echo 'stripos is faster' . PHP_EOL; } ?> -nathan

« previous php.general (#275021) next »