Re: Limitations of preg_replace?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 25/10/2007, Werner Schneider <wuschba@xxxxxxxx> wrote:
> Hi.
>
> Are there any limitations of preg_replace and is there
> a way to change them (for example with ini_set)?
>
> I got a php 4.4.7 on a linux-webhoster which crashes
> without error-message on this script:
> <?php
>         $txt = "";
>         for ($i = 0; $i < 2000; $i++)
>         {       $txt .= "<a href=\"helloworld.htm\" title=\"my
> title\"><img src=\"/mypic.jpg\"></a><br />\n";
>         }
>         $txt =
> preg_replace("/<a(.*)href=\"\\index.htm\">/isU",
> "<a$1href=\"\\\">", $txt);
>         print $txt;
> ?>
> If I loop only 1000 times or don't use (.*)->$1 on the
> regular expression, it works. It works as well on a
> local WAMP-Installation.
>
> Any ideas about that?

Yeah, the backtrack limit.

But
   1. it's not configurable in PHP 4
   2. You'd be better off writing your regexp so it doesn't have to
backtrack all the way
       through a 150KB string.

Try replacing .* with [^>]*

-robin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux