Re: Verifying a certain amount of numbers

From: Date: Wed, 16 Jul 2003 14:17:06 +0000
Subject: Re: Verifying a certain amount of numbers
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-155426@lists.php.net to get a copy of this message
Justin French <justin@indent.com.au> wrote: > If you care about performance at all, try and find away around the > problem without regular expressions... > > I tested > > if( (strlen($str) == 6) && (is_int($str)) ) > > vs > > if(ereg('^[0-9]{6}$',$str)) > > > ...on my LAN test server with 100000 iterations, and the regexp was > nearly 2 times slower than the first solution. IMHO, it's also faster Excellent point! I find my self using regex's a bit to often when there are other solutions available. btw, have you ever tested the difference between if(ereg('^[0-9]{6}$',$str)) if(preg_grep('^[0-9]{6}$',$str)) I've been meaning to find out advantages/disadvantages with PERL vs. POSIX compatible. Curt. --

« previous php.general (#155426) next »