note 74542 added to function.preg-match
| From: | legolas558d0tusersdotsfdotnet at osu1 dot php dot net | Date: | Mon, 16 Apr 2007 17:16:00 +0000 |
| Subject: | note 74542 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125480@lists.php.net to get a copy of this message | ||
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>';
?>
----
Server IP: 213.92.11.19
Probable Submitter: 151.75.184.30
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/74542
Del: integrated -- https://master.php.net/note/delete/74542/integrated
Del: useless -- https://master.php.net/note/delete/74542/useless
Del: bad code -- https://master.php.net/note/delete/74542/bad+code
Del: spam -- https://master.php.net/note/delete/74542/spam
Del: non-english -- https://master.php.net/note/delete/74542/non-english
Del: in docs -- https://master.php.net/note/delete/74542/in+docs
Del: other reasons-- https://master.php.net/note/delete/74542
Reject -- https://master.php.net/note/reject/74542
Search -- https://master.php.net/manage/user-notes.php