php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44621 preg_split with NO_EMPTY is buggy when splitting on greedy patterns
Submitted: 2008-04-02 21:53 UTC Modified: 2008-04-02 22:36 UTC
From: mpb dot mail at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.5 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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mpb dot mail at gmail dot com
New email:
PHP Version: OS:

 

 [2008-04-02 21:53 UTC] mpb dot mail at gmail dot com
Description:
------------
preg_split with PREG_SPLIT_NO_EMPTY is buggy when splitting on greedy patterns.

See reproduce code.

preg_split in PHP 4.4.8 similarly buggy.


Reproduce code:
---------------
<?php

$s = "  1   2 3  ";

print_r (preg_split ("/ +/", $s));
print_r (preg_split ("/ +/", $s, PREG_SPLIT_NO_EMPTY));

?>


Expected result:
----------------
Array
(
    [0] => 
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 
)
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)


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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-02 22:36 UTC] felipe@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

The third parameter is to set the limit.

array preg_split ( string $pattern , string $subject [, int $limit [, int $flags ]] )
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Sep 29 00:01:26 2024 UTC