Bug #18341 Updated: problem w/ preg_split re: limit and chr(0)

From: Date: Sun, 14 Jul 2002 22:37:20 +0000
Subject: Bug #18341 Updated: problem w/ preg_split re: limit and chr(0)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-14162@lists.php.net to get a copy of this message
ID: 18341 Updated by: andrei@php.net Reported By: nospam@1111-internet.com -Status: Open +Status: Closed Bug Type: PCRE related Operating System: FreeBSD 4.0 PHP Version: 4.2.1 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2002-07-14 16:23:33] nospam@1111-internet.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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18341&edit=1

« previous php.bugs (#14162) next »