php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31895 PREG_SPLIT_DELIM_CAPTURE returns delimiter twice
Submitted: 2005-02-09 13:53 UTC Modified: 2005-06-28 22:55 UTC
From: peter dot bauwens at b-rail dot be Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5CVS, 4CVS (2005-05-30) OS: *
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: peter dot bauwens at b-rail dot be
New email:
PHP Version: OS:

 

 [2005-02-09 13:53 UTC] peter dot bauwens at b-rail dot be
Description:
------------
If you use preg_split with the PREG_SPLIT_DELIM_CAPTURE flag, the delimiter is returned twice.

This bug also occurs in PHP 5.0.3.

I only added mssql and cpdf support in php.ini (has no relevance, I think).

Reproduce code:
---------------
<?php
  $From = "HR_PersFunUit LEFT JOIN HR_Pers ON HR_PersFunUit.IDNR = HR_Pers.IDNR";
  $Stukken = preg_split("/(( LEFT JOIN )|( RIGHT JOIN )|( INNER JOIN )|( ON ))/", $From, -1, PREG_SPLIT_DELIM_CAPTURE);
  print_r($Stukken);
?>

Expected result:
----------------
Array
(
    [0] => HR_PersFunUit
    [1] =>  LEFT JOIN 
    [2] => HR_Pers
    [3] =>  ON 
    [4] => HR_PersFunUit.IDNR = HR_Pers.IDNR
)


Actual result:
--------------
Array
(
    [0] => HR_PersFunUit
    [1] =>  LEFT JOIN 
    [2] =>  LEFT JOIN 
    [3] => HR_Pers
    [4] =>  ON 
    [5] => 
    [6] => 
    [7] => 
    [8] =>  ON 
    [9] => HR_PersFunUit.IDNR = HR_Pers.IDNR
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-09 22:39 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Works fine on Win32 and Linux when I tried the given code.
 [2005-02-10 08:37 UTC] peter dot bauwens at b-rail dot be
The bug still occurs in this snapshot of PHP 4.3.11-dev(Win32, same result).
I used the 'php.ini-recommended' as php.ini (didn't change a thing in it).
Is there any way to get more info to help you? (I also know C, C++, ASM if it helps in any way)
 [2005-02-10 15:00 UTC] sniper@php.net
Are you absolutely sure you've installed the new PHP version correctly ?? Make sure you remove _all_ previous dlls related to PHP before you install the new ones from the snapshot.

 [2005-02-10 15:10 UTC] peter dot bauwens at b-rail dot be
I used a totally different directory for the PHP snapshot, 
copied the php.ini in the Windows-dir, 
I changed my path in the httpd.conf of my Apache2 server, and restarted the server.
In phpinfo() I got the 'version 4.3.11-dev'...
 [2005-02-10 15:16 UTC] peter dot bauwens at b-rail dot be
I just found out something new (I hope it helps)
If I try these 2 lines:

$String = "test 12 test 123 test 123 test";
print_r(preg_split("/( 12(3){0,1} )/", $String, -1, PREG_SPLIT_DELIM_CAPTURE));

I get this as result: 
Array
(
    [0] => test
    [1] =>  12 
    [2] => test
    [3] =>  123 
    [4] => 3
    [5] => test
    [6] =>  123 
    [7] => 3
    [8] => test
)
 [2005-02-11 05:52 UTC] sniper@php.net
Verified.

 [2005-06-27 01:22 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

PCRE was upgraded to version 5.0.
 [2005-06-28 22:13 UTC] peter dot bauwens at b-rail dot be
I tried the Win32 snapshot, but the bug still exists.
The recognicion is good, but I get to much return-values...
 [2005-06-28 22:55 UTC] nlopess@php.net
This is totally bogus, because you are using capturing parentheses. If you change the supplied test cases to (?:) they will work as expected.

Lets see test #2:
$String = "test 12 test 123 test 123 test";
print_r(preg_split("/( 12(?:3){0,1} )/", $String, -1, PREG_SPLIT_DELIM_CAPTURE)); // note the ?: there

outputs:
(
    [0] => test
    [1] =>  12
    [2] => test
    [3] =>  123
    [4] => test
    [5] =>  123
    [6] => test
)

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 06:01:30 2025 UTC