php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20528 preg_split drops characters (re-opens Bug #15413)
Submitted: 2002-11-20 19:15 UTC Modified: 2002-11-21 17:52 UTC
From: ianm at judcom dot nsw dot gov dot au Assigned:
Status: Closed Package: PCRE related
PHP Version: 4.3.0-dev/4.4.0-dev OS: win32 and linux
Private report: No CVE-ID: None
 [2002-11-20 19:15 UTC] ianm at judcom dot nsw dot gov dot au
SUMMARY: preg_split incorrectly drops the first character of the last element of the array it creates, at least in some circumstances. The equivalent Perl code works correctly, and drops no characters.

[the following stuff has been copied from my comment to Bug #15413, which I cannot re-open as I am not the owner]

The following code splits and re-joins a string - it should produce the original string but doesn't.

$foo = '(#11/19/2002#)';   // MS Access date constant
$bar = preg_split('/\b/',$foo);
$baz = join('',$bar);
print $baz;

result is: (#11/19/2002)

The trailing hash character (#) is being dropped.

I tried the equivalent program in Perl (see below) and it produces the *correct* result - so it is not a problem with the regex itself.

(Perl source:)
$foo = '(#11/19/2002#)';   # MS Access date constant
@bar = split(/\b/,$foo);
$baz = join('',@bar);
print $baz;

result is: (#11/19/2002#)

I have experienced this problem on Win32 with PHP 4.2.3 and 4.1.2, and on Linux with PHP 4.04pl1 (RH7.1). The equivalent Perl code works correctly on both Win32 (Perl 5.6.1) and Linux (Perl 5.6.0).

[NOTE: the person who originally reported this bug provided a much more complicated example. Apart from his and my examples, I don't know if any other circumstances can trigger this bug.]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-21 17:52 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 19:01:30 2024 UTC