Page 1 of 1

preg_match bug in PHP 5.2.1 ?

Posted: Fri May 11, 2007 10:41 pm
by anjanesh
Hi

I was updating a RegExp pattern recently and I was breaking my head trying to figure out why $matches of preg_match was returning an empty array always.

I tried this on a server having php version 4 and it worked !

Code: Select all

<pre>
<?php
// preg_match bug in php-5.2.1.php ?
$URL = "http://feedback.ebay.com/ws/eBayISAPI.dll?ViewFeedback2&userid=quality_coins_and_currency&ftab=FeedbackAsSeller&items=200&page=1";
$contents = file_get_contents($URL);
if ($contents === FALSE) die("Couldnt retrieve http contents");

preg_match('#<table border="0" cellpadding="0" cellspacing="0" width="100%" class="fbOuter">(.*?)</table>#is', $contents, $matches);
print_r($matches);
?>
Returns an empty array in PHP 5.2.1 but otherwise returns the pattern-matched array (Tested and works in versions 4.4.4, 4.3.11).

Im going to update to 5.2.2, but does ver 5.2.2 have PCRE Library Version greater than 6.7 04-Jul-2006 ? Isnt this dependant on the PCRE version alone ?

Posted: Sat May 12, 2007 5:46 am
by Chris Corbyn
There are subtleties in the size of a string you can match. This is affected by PCRE_MATCH_LIMIT at compile time if I remember correctly. This causes the pattern to appear not to match.

Posted: Sat May 12, 2007 6:39 am
by anjanesh
Im finding it difficult to believe that its because of PCRE_MATCH_LIMIT flag. The string to match isn't all that long.
If this is the cause, is there any way to change this value (also view this in some config file ?) in Linux and Windows ?

Thanks

From PHP Bugs,
It's PCRE limitation, from PCRE docs:

"The maximum length of a subject string is the largest
positive number that an integer variable can hold. However,
PCRE uses recursion to handle subpatterns and indefinite
repetition. This means that the available stack space may
limit the size of a subject string that can be
processed by certain patterns."

Given long enough subject string, it will crash with PHP 5.0.x, PHP
5.1.x..