note 34009 added to function.explode
| From: | ralfoide at rack1 dot php dot net | Date: | Sun, 13 Jul 2003 20:02:42 +0000 |
| Subject: | note 34009 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52035@lists.php.net to get a copy of this message | ||
Using 1 or less for the "limit" may not yield the result you expect. I'm using PHP
4.1.2
I had surprising results when using explode() or split() with a "limit" of 0 or 1: in this
case the returned array contains one entry with the full "remaining" string.
Ex:
$a = explode("/", "a/b/c", 1); var_dump($a);
=> array(1) { [0]=> string(5) "a/b/c" }
$a = explode("/", "a/b/c", 2); var_dump($a);
=> array(2) { [0]=> string(1) "a" [1]=> string(3) "b/c" }
Using limit=0 behaves as in limit=1 above.
It seems the implementation uses limit as the number of elements to return, including the
"remaining string", whereas the doc seems to describe it as indicating the number of
separators to process (i.e. the resulting array should contain limit+1 entries).
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34009
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34009&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34009&report=yes