preg_match bug in PHP 5.2.1 ?

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

preg_match bug in PHP 5.2.1 ?

Post 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 ?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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..
Post Reply