|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-05-09 18:36 UTC] 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:
Patchesadd-bigger-RegEx-engine (last revision 2010-05-09 16:43 UTC by trevor at ridgebizdev dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 20:00:01 2025 UTC |
preg_last_error() has been available only for months with PHP 5.2.0. If you notice my style of ${1}, you know I've been using these functions since before 5.2.0. Who demanded preg_last_error() and when? Why don't the preg_ functions use preg_last_error()? preg_last_error() is working, but it's only half of the process of finishing the preg_ functions. Whether the expression fails to match or if the expression engine crashes (which sounds like failing to match) then the argument string is the return value--not the empty string. Do you dig it?