php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42806 preg_replace returns empty string
Submitted: 2007-10-01 01:00 UTC Modified: 2007-10-01 09:11 UTC
From: jm at mayfirst dot org Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.4 OS: gnu linux/debian sid
Private report: No CVE-ID: None
 [2007-10-01 01:00 UTC] jm at mayfirst dot org
Description:
------------
When executing preg_replace on a string over 32,205 bytes and no double line breaks with the following expression, the function neither matches nor returns the original string. preg_last_error() doesn't indicate any  preg related errors.

Reproduce code:
---------------
 error_reporting(E_ALL);
  $original_string = "This is a preg_replace bug.\n";
  $string = '';
  $i = 0;
  while($i < 1177) {
    $string .= $original_string;
    preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "foo", $string,-1,$count);
    if($count == 0) {
      echo "I broke at count: $i\n";
      exit;
    }
    $i++;
  }
  echo "I didn't break at count: $i\n";
  echo preg_last_error();


Expected result:
----------------
I didn't break at count: 1176.

Actual result:
--------------
I broke at count: 1176

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-01 09:11 UTC] scottmac@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Within the loop if $count equals 0 you exit without calling preg_last_error();

If you had a preg_last_error call there you get int(2) which means PREG_BACKTRACK_LIMIT_ERROR

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 12:01:31 2024 UTC