|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42678 reg_replace returns empty string on certain data
Submitted: 2007-09-15 19:15 UTC Modified: 2007-09-15 19:31 UTC
From: jana dot vasseru at gmail dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 5.2.4 OS: W2000
Private report: No CVE-ID: None
 [2007-09-15 19:15 UTC] jana dot vasseru at gmail dot com
On certain data preg_replace() returns empty string. The code below works correctly on PHP 5.1.6

Reproduce code:

$data = file_get_contents('src.sql');
echo strlen($data).'<br>';
$data = preg_replace("#INSERT\\sINTO([\\s\\S]*?)INSERT\\sINTO#", "\$DELTA_SCRIPT[] = 'INSERT INTO\\1'; \$DELTA_SCRIPT[] = 'INSERT INTO", $data);
$data = preg_replace("#CREATE\\sTABLE([\\s\\S]*?)[^']INSERT\\sINTO#", "CREATE TABLE \\1 \$DELTA_SCRIPT[] = 'INSERT INTO", $data);
echo strlen($data); //returns 0 here


Expected result:
Return whatever but empty string.

Actual result:
Returns empty string.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-15 19:17 UTC] jana dot vasseru at gmail dot com
The exact text file triggering the error can be found here:
163 337 byte
 [2007-09-15 19:31 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Check preg_last_error() you've probably hit one of the limits to stop you smashing the stack.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 08:01:27 2024 UTC