php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48047 preg_replace returns NULL over string size
Submitted: 2009-04-22 13:53 UTC Modified: 2009-04-22 13:58 UTC
From: goriol at technema dot fr Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 5.2.9 OS: Windows XP
Private report: No CVE-ID: None
 [2009-04-22 13:53 UTC] goriol at technema dot fr
Description:
------------
I found a situation where preg_replace returns NULL instead of the expected string. The regexp I use is (perhaps) erroneous: "/^\s*(.*?)\s*$/s"
But when the string size is less than 49997 characters, the function returns the string properly. Over that size, the function returns NULL.

Reproduce code:
---------------
$a = str_repeat('a', 49998);
$a = preg_replace('/^\s*(.*?)\s*$/s', '$1', $a);


Expected result:
----------------
$a

Actual result:
--------------
NULL

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-22 13:58 UTC] scottmac@php.net
preg_last_error() returns 2 which is PREG_BACKTRACK_LIMIT_ERROR.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC