Re: Remove punctuation

From: Date: Thu, 09 Sep 2004 19:12:39 +0000
Subject: Re: Remove punctuation
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-196245@lists.php.net to get a copy of this message
John Nichel wrote:
Jason Davidson wrote:
i think str_replace is faster that ereg_replace Jason
We tested that theory a while back on here (I don't remember the subject of the emails, so finding it would be kind of hard), and it came out to be almost exactally the same speed.
Around 1/10th of a second difference in 100,000 replaces.... <?php function getmicrotime() { list( $usec, $sec ) = explode( " ", microtime() ); return ( ( float ) $usec + ( float ) $sec ); } $string = "Foo is a common term used in programming."; $start = getmicrotime(); for ( $i = 0; $i < 100000; $i++ ) { preg_replace ( "/Foo/", "Bar", $string ); } $stop = getmicrotime(); $preg = $stop - $start; $start = getmicrotime(); for ( $i = 0; $i < 100000; $i++ ) { str_replace ( "Foo", "Bar", $string ); } $stop = getmicrotime(); $strreplace = $stop - $start; echo ( "PREG : " . $preg . "<br />\nSTR_ : " . $strreplace ); ?> -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 john@kegworks.com

« previous php.general (#196245) next »