Edit report at https://bugs.php.net/bug.php?id=65396&edit=1

 ID:                 65396
 Updated by:         a...@php.net
 Reported by:        empaingeo at hotmail dot com
 Summary:            Separators at the beginning of string are also
                     exploded
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Strings related
 Operating System:   Windows Vista
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

or additionally to trim, preg_replace(',\s+,', ' ', $str)


Previous Comments:
------------------------------------------------------------------------
[2013-08-07 21:42:08] empaingeo at hotmail dot com

Hi, thanks for the reply. I will follow your advice.

Best regards.

------------------------------------------------------------------------
[2013-08-07 20:36:54] mail+php at requinix dot net

Totally intended and often desirable behavior.

If you don't want those then trim() the spaces off first, or if you're worried 
about multiple spaces inside the string too ("test1   test2") then 
array_filter() 
the result.

------------------------------------------------------------------------
[2013-08-05 23:39:25] empaingeo at hotmail dot com

Description:
------------
---
>From manual page: 
>http://www.php.net/function.explode#refsect1-function.explode-returnvalues
---

Hi, to reproduce the problem :



Test script:
---------------
<?php
        echo "<pre>";
        echo print_r(explode(' ', "    test1 test2"));
        echo "</pre>";
?>

Expected result:
----------------
Array
(
    [0] => test1
    [1] => test2
)
1

Actual result:
--------------
Array
(
    [0] => 
    [1] => 
    [2] => 
    [3] => 
    [4] => test1
    [5] => test2
)
1


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65396&edit=1

Reply via email to