note 71271 added to function.explode
| From: | phpdocatjeudidotde at osu1 dot php dot net | Date: | Mon, 20 Nov 2006 13:28:39 +0000 |
| Subject: | note 71271 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119900@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 217.13.201.10
Probable Submitter: 88.73.247.183
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- https://master.php.net/note/edit/71271
Del: integrated -- https://master.php.net/note/delete/71271/integrated
Del: useless -- https://master.php.net/note/delete/71271/useless
Del: bad code -- https://master.php.net/note/delete/71271/bad+code
Del: spam -- https://master.php.net/note/delete/71271/spam
Del: non-english -- https://master.php.net/note/delete/71271/non-english
Del: in docs -- https://master.php.net/note/delete/71271/in+docs
Del: other reasons-- https://master.php.net/note/delete/71271
Reject -- https://master.php.net/note/reject/71271
Search -- https://master.php.net/manage/user-notes.php