|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28755 preg_split doesn't behave as expected for empty tokens
Submitted: 2004-06-12 15:56 UTC Modified: 2004-06-12 16:14 UTC
From: ekitten-listed at comcast dot net Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 4.3.6 OS: Linux
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: ekitten-listed at comcast dot net
New email:
PHP Version: OS:


 [2004-06-12 15:56 UTC] ekitten-listed at comcast dot net
If I call preg_split with a string such as ",,foo,,bar,," I expect to get five empty strings back in the returned array, but I only get back two - the first and the last.

Reproduce code:
$tokens = preg_split("/[,]+/", ",,foo,,bar,,");

Expected result:
I expect $tokens to contain the following array:

array(12) {
  [0]=>  string(0) ""
  [1]=>  string(0) ""
  [2]=>  string(3) "foo"
  [3]=>  string(0) ""
  [4]=>  string(3) "bar"
  [5]=>  string(0) ""
  [6]=>  string(0) ""

Actual result:
array(12) {
  [0]=>  string(0) ""
  [1]=>  string(3) "foo"
  [2]=>  string(3) "bar"
  [3]=>  string(0) ""


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-12 16:14 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

Your scrupt is wrong, [,]+ will also match \",,\" and that will be used to split your script, and not two single \",\"\'s.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 13:01:28 2024 UTC