php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18341 problem w/ preg_split re: limit and chr(0)
Submitted: 2002-07-14 16:23 UTC Modified: 2002-07-14 18:37 UTC
From: nospam at 1111-internet dot com Assigned:
Status: Closed Package: PCRE related
PHP Version: 4.2.1 OS: FreeBSD 4.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nospam at 1111-internet dot com
New email:
PHP Version: OS:

 

 [2002-07-14 16:23 UTC] nospam at 1111-internet dot com
When using the limit parameter on preg_split(), the last element of the resulting array is truncated at chr(0) (if there is one) instead of extending to the end of the source string as it should. The same problem is not found in explode().

The following code snippet demonstrates the problem:

<?php
$string="a1a-b2b-c". chr(0). "c-d4d-e5e-f6f";

list($a1a, $b2b, $rest)=explode("-", $string, 3);
echo "explode: ", strlen($rest);
    // should be, and is, 15

echo "<br>\n"; // for html aesthetics only

list($a1a, $b2b, $rest)=preg_split("/-/", $string, 3);
echo "preg_split: ", strlen($rest);
    // should be 15, actually is 1 because it terminates at the chr(0)
?>

The problem doesn't appear to affect any of the elements except the last one when limit is used.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-14 18:37 UTC] andrei@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version 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.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC