note 71271 deleted from function.explode by tularis
| From: | tularis@php.net | Date: | Mon, 20 Nov 2006 14:27:53 +0000 |
| Subject: | note 71271 deleted from function.explode by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119903@lists.php.net to get a copy of this message | ||
Note Submitter: phpdoc at jeudi dot de
Reason: useless
----
As ian at illumen pointed out, exploding empty strings results in a one-element array, a behaviour
you want to fix on many occasions, either by including an extra test for empty strings, or by using
preg_split. I found preg_split with the PREG_SPLIT_NO_EMPTY switch to be 3 times slower than explode
with an extra test. Comparing expression (1) and (2),
(1): ($a?explode("\t",$a):array())
(2): preg_split("/\t/","",-1,PREG_SPLIT_NO_EMPTY)
looping through 1M repetitions on an AMD box running php4-cli under linux, (2) took 2.7 seconds
while (1) took 1 second.