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

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-22 13:58 UTC]
preg_last_error() returns 2 which is PREG_BACKTRACK_LIMIT_ERROR.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 19:01:28 2024 UTC