Edit report at http://bugs.php.net/bug.php?id=51777&edit=1
ID: 51777 Updated by: m...@php.net Reported by: trevor at ridgebizdev dot com Summary: RegEx matching fails -Status: Open +Status: Feedback Type: Bug Package: PCRE related Operating System: Windows XP and Linux Server PHP Version: 5.3.2 New Comment: Please try using this snapshot: http://snaps.php.net/php5.3-latest.tar.gz For Windows: http://windows.php.net/snapshots/ Works here. Do you have a pcre.backtrack_limit set? Previous Comments: ------------------------------------------------------------------------ [2010-05-09 18:36:54] trevor at ridgebizdev dot com Description: ------------ When a RegEx "looks" over ~32768 times during a successful match, every RegEx function fails and returns the empty string. Test script: --------------- <?php $response = http_get("http://www.travelocity.com"); // no problem with these first 2 RegExs $response2 = preg_replace('/\s+/'," ",$response); $mytitle = preg_replace('/.*?<\s*title\s*>([^<]*)<.*/i','${1}',$response2); echo "\nTitle Match Forward: ".$mytitle."\n\n"; // now, here's a problem $mytitle2 = preg_replace('/.*<\s*title\s*>([^<]*)<.*/i','${1}',$response2); echo "\nTitle Match Backward: ".$mytitle2."\n\n"; ?> Expected result: ---------------- $mytitle gets extracted properly and echoed because the RegEx never looks more than 32768 times starting at the beginning of the travelocity.com page source. $mytitle2 never gets extracted because the RegEx looks more than 32768 times successfully and preg_replace() crashes into the empty string. Matching forward for the title is working; matching backward for the title is failing for large buffers. Actual result: -------------- Title Match Forward: Travelocity Travel: Airline Tickets, Hotels, Flights, Vacations, Cruises & Car Rentals Title Match Backward: ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51777&edit=1