|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65396 Separators at the beginning of string are also exploded
Submitted: 2013-08-05 23:39 UTC Modified: 2013-08-10 22:23 UTC
From: empaingeo at hotmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: Irrelevant OS: Windows Vista
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: empaingeo at hotmail dot com
New email:
PHP Version: OS:


 [2013-08-05 23:39 UTC] empaingeo at hotmail dot com
From manual page:

Hi, to reproduce the problem :

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

Expected result:
    [0] => test1
    [1] => test2

Actual result:
    [0] => 
    [1] => 
    [2] => 
    [3] => 
    [4] => test1
    [5] => test2


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-07 20:36 UTC] 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-07 21:42 UTC] empaingeo at hotmail dot com
Hi, thanks for the reply. I will follow your advice.

Best regards.
 [2013-08-10 22:23 UTC]
-Status: Open +Status: Not a bug
 [2013-08-10 22:23 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

or additionally to trim, preg_replace(',\s+,', ' ', $str)
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Oct 01 13:01:24 2023 UTC