ID: 48692 Comment by: sjoerd-php at linuxonly dot nl Reported By: estudiosima at gmail dot com Status: Open Bug Type: *General Issues Operating System: ubuntu 8.04 PHP Version: 5.2.10 New Comment:
Thank you for your bug report. The behavior you describe is by design. If there are n delimeters, explode() returns n+1 elements. It splits the string using a space, and thus also splits using the first space. Because there is nothing before the first space, the first element of the array is empty. In this case, you can first trim() the string to remove spaces. Previous Comments: ------------------------------------------------------------------------ [2009-06-25 13:42:59] estudiosima at gmail dot com Description: ------------ if the string have a space in the begin of the string, takes the space as a word. Reproduce code: --------------- --- >From manual page: function.explode --- <? phpinfo(); $a = " word1 word2"; $b = explode(" ",$a); print_r($b); print "<br>".count($b); /* result: Array ( [0] => [1] => word1 [2] => word2 ) 3 */ ?> Expected result: ---------------- Array ( [0]=>word1 [1]=>word2 ) Actual result: -------------- Array ( [0] => [1] => word1 [2] => word2 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48692&edit=1