Re: Remove punctuation
| From: | John Holmes | Date: | Thu, 09 Sep 2004 19:27:03 +0000 |
| Subject: | Re: Remove punctuation | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196247@lists.php.net to get a copy of this message | ||
From: "John Nichel" <john@kegworks.com>
Not that speed tests like this really matter in the long run of your code, but: str_replace: 0.26480603218079 ereg_replace: 0.61685109138489 preg_replace came in at about 0.4, btw ---John Holmes... Code: <?php function gt() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $str = 'It\'s, all! ok? asd? asdf! " and " wosz'; $s1 = gt(); for($i = 0; $i < 50000; $i++) { str_replace(array('.',',','!','?','"','\''),'',$str); } $e1 = gt(); $s2 = gt(); for($i = 0; $i < 50000; $i++) { ereg_replace("[.,!?\"']",'',$str); } $e2 = gt(); echo 'str_replace: ' . ($e1 - $s1) . '<br />ereg_replace: ' . ($e2-$s2); ?>i think str_replace is faster that ereg_replaceWe 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.