note 74542 deleted from function.preg-match by nlopess
| From: | nlopess@php.net | Date: | Tue, 01 May 2007 13:31:27 +0000 |
| Subject: | note 74542 deleted from function.preg-match by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126026@lists.php.net to get a copy of this message | ||
Note Submitter: legolas558 d0t users dot sf dot net
----
I have posted this note on the bug tracker and also here because it might help a lot of users
experiencing 500 server errors when using preg_match_all or preg_match. If the PHP script worked
fine until the latest PHP update (which now bundles with PCRE version 7), then you might have a
regex problem. See also http://bugs.php.net/bug.php?id=41050 and similar;
this bug is marked as a PCRE bug, so you can experience it on any PHP4/PHP5 (under any OS) with
PCRE7.
I found a workaround for my own problem, maybe it will help other users too.
<?php
// by legolas558
// core regex expression (without leading and trailing slash)
$regex = "(?i:begin|start)\\s+([^']*('[^']*')*)*";
$old_php_regex = "/".$regex."/";
// notice the greedy/ungreedy change which actually works around the segmentation fault
$bug41050_regex = "/".$regex."?/";
// test case
$subject = "begin\nnon string 'string' other non string";
// will work on any PHP - also the latest versions with PCRE7
preg_match_all($bug41050_regex, $subject, $m);
echo '<pre>';var_dump($m);echo '</pre>'; unset($m);
// will cause a segmentation fault (and so a 500 server error) if used on PHP versions compiled with
PCRE7
// preg_match_all($old_php_regex, $subject, $m);
echo '<pre>';var_dump($m);echo '</pre>';
?>