|  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
 [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:

$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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-14 18:37 UTC]
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at In case this was a documentation 
problem, the fix will show up soon at
In case this was a website problem, the change will show
up on the site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 24 12:03:37 2021 UTC