php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50463 PREG_SPLIT eating character
Submitted: 2009-12-12 22:21 UTC Modified: 2009-12-12 22:44 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bellingan at email dot it Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.1 OS: Suse Linux 11.2
Private report: No CVE-ID: None
 [2009-12-12 22:21 UTC] bellingan at email dot it
Description:
------------
PREG_SPLIT whit the PREG_SPLIT_DELIM_CAPTURE flag, return the matched string dropping the first charcater.
Like in http://bugs.php.net/bug.php?id=15413&edit=2

Reproduce code:
---------------
$via="123Gatano_Rizzi";
$res=preg_split("/[a-z]../",$via,PREG_SPLIT_DELIM_CAPTURE);
var_dump($res);

Expected result:
----------------
array(2) {
  [0]=>
  string(4) "123G"
  [1]=>
  string(3) "ata"
  [2]=>
  string(8) "no_Rizzi"
}


Actual result:
--------------
array(2) {
  [0]=>
  string(4) "123G"
  [1]=>
  string(8) "no_Rizzi"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-12 22:22 UTC] bellingan at email dot it
Sorry it doesen't return at all the matched text...
 [2009-12-12 22:31 UTC] felipe@php.net
The third param. is for the 'limit', not for flags.
See the examples in the documentation.
 [2009-12-12 22:44 UTC] bellingan at email dot it
$res=preg_split("/[a-z]../",$via,-1,PREG_SPLIT_DELIM_CAPTURE);
Yes...

Now is even more oddy...
Giving
array(4) {
  [0]=>
  string(4) "123G"
  [1]=>
  string(0) ""
  [2]=>
  string(1) "R"
  [3]=>
  string(1) "i"
}

Now I'm using the 
preg_match("/[a-z]..+/",$via,$res,PREG_OFFSET_CAPTURE);
dump($m);
giving a 

Array
(
    [0] => Array
        (
            [0] => ata
            [1] => 4
        )

)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 02:01:29 2024 UTC