php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ekitten-listed at comcast dot net
New email:
PHP Version: OS:

 

 [2004-06-12 15:56 UTC] ekitten-listed at comcast dot net
Description:
------------
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) ""
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-12 16:14 UTC] derick@php.net
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

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: Wed Apr 24 05:01:30 2024 UTC