Moving text around in file causes unexplainable behaviour.
Posted: Sun Jun 11, 2006 1:03 pm
Greetings!
I am looking at some code, and while I understand most of it, I don't understand the following thing:
A php-file opens a HTML-file (using fopen) and the content is saved in a string. Then, two lines of ereg_replace looks for particular patterns in the string (see below).
// $a is a string that contains whatever is <!-- BEGIN a --> and <!-- END a -->.
$a = ereg_replace( "^.*<!-- BEGIN a -->(.*)<!-- END a -->.*$", "\\1", $b);
// $b is a string that contains any text outside $a, and replaces the content of $a with $randomtime
$randomtime = md5( microtime() );
$b = ereg_replace( "<!-- BEGIN a -->.*<!-- END a -->", $randomtime, $b );
Before and after <!-- BEGIN a --> and <!-- END a -->, there's helluva lots of text. Now, if I move the lines <!-- BEGIN a --> and <!-- END a --> and the text between them near the top of the file, I get the error "Fatal error: Maximum execution time of 30 seconds exceeded" (tried extending to 120s).
I'm not a regex expert, but it looks to me that the regex expression doesn't care where the searched text is located in the file. Can anyone explain why I get the fatal error?[/i]
I am looking at some code, and while I understand most of it, I don't understand the following thing:
A php-file opens a HTML-file (using fopen) and the content is saved in a string. Then, two lines of ereg_replace looks for particular patterns in the string (see below).
// $a is a string that contains whatever is <!-- BEGIN a --> and <!-- END a -->.
$a = ereg_replace( "^.*<!-- BEGIN a -->(.*)<!-- END a -->.*$", "\\1", $b);
// $b is a string that contains any text outside $a, and replaces the content of $a with $randomtime
$randomtime = md5( microtime() );
$b = ereg_replace( "<!-- BEGIN a -->.*<!-- END a -->", $randomtime, $b );
Before and after <!-- BEGIN a --> and <!-- END a -->, there's helluva lots of text. Now, if I move the lines <!-- BEGIN a --> and <!-- END a --> and the text between them near the top of the file, I get the error "Fatal error: Maximum execution time of 30 seconds exceeded" (tried extending to 120s).
I'm not a regex expert, but it looks to me that the regex expression doesn't care where the searched text is located in the file. Can anyone explain why I get the fatal error?[/i]