Doc #51864 [Opn->Fbk]: preg_replace returns NULL on error

From: Date: Thu, 20 May 2010 12:31:29 +0000
Subject: Doc #51864 [Opn->Fbk]: preg_replace returns NULL on error
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-4409@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51864&edit=1 ID: 51864 Updated by: mike@php.net Reported by: dscotese at litmocracy dot com Summary: preg_replace returns NULL on error -Status: Open +Status: Feedback Type: Documentation Problem -Package: Regexps related +Package: PCRE related Operating System: NA PHP Version: Irrelevant New Comment: Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. Previous Comments: ------------------------------------------------------------------------ [2010-05-20 00:45:22] dscotese at litmocracy dot com Description: ------------ Sometimes preg_replace([Array],[Array],$subject) returns null, but the error cannot be reproduced using preg_replace($problem_regex,$repl,$subject). My attempt to reproduce it showed that $problem_regex was not a problem - the replacement worked as designed. I actually removed it from the arrays and did it separately under the assumption that the regex engine might have been biting off more than it could chew. If I shortened $repl, I was able to get the array version to work, but since my $repl was longer, I moved it to a separate call. The docs for preg_replace do not mention preg_last_error. That should be mentioned right where it says it returns NULL on error. Test script: --------------- // You may need to create several more patterns and replacements to get an error // Just make sure they're all legitimate $contents = file_get_contents("textfile.txt"); $find = array('<td><'.'?php readfile("/var/www/www.domain1.com/html/templates/leftmenu2_lfl.txt"); ?'.'></td><td width="663"', '#(?:<table .{450,500})?<\?php\s+readfile[^<>]*?templates/footer(?:lamps)?.txt[\'";) ]*\s*\?'.'>.*#s'); $replace = array('<td>file_get_contents('whatever').'</td><td width="601"', file_get_contents('newFooter.txt')); echo preg_replace($find, $replace, $contents); Expected result: ---------------- When the arrays are large enough and/or the patterns are complicated enough, The output will be empty. The "bug" is that there's no documentation on how to find out why it's empty. Is there a way? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51864&edit=1

« previous php.doc.bugs (#4409) next »