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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 - 14 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 26 12:01:30 2024 UTC