#48692 [Com]: error in response

From: Date: Thu, 25 Jun 2009 19:59:04 +0000
Subject: #48692 [Com]: error in response
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-138836@lists.php.net to get a copy of this message
 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



Thread (3 messages)

« previous php.bugs (#138836) next »