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]
Moving text around in file causes unexplainable behaviour.
Moderator: General Moderators
-
photonatic
- Forum Newbie
- Posts: 8
- Joined: Thu Jun 08, 2006 4:44 pm
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
I'd need to see the full script to be able to see that.
The first pattern you've posted seems to be looking at an entire string from start to end and the pattern should match the whole thing. The second pattern is a bit looser in that the string can occur anywhere in the document.
Now, perhaps the first pattern you've posted is looking at some material that's been pulled out from somewhere else? I can't really say without seeing more code
The first pattern you've posted seems to be looking at an entire string from start to end and the pattern should match the whole thing. The second pattern is a bit looser in that the string can occur anywhere in the document.
Now, perhaps the first pattern you've posted is looking at some material that's been pulled out from somewhere else? I can't really say without seeing more code
-
photonatic
- Forum Newbie
- Posts: 8
- Joined: Thu Jun 08, 2006 4:44 pm
Hi d11wtq.
I figured out in the end what was wrong. Actually, there was nothing wrong with the code, but I guess, that moving the text the regex was looking for, further to the top in the html-file extended the time to find them. At a point it would take too much time to search for the pattern, and thus I got the error message. I found out by moving the text bit-by-bit upwards until the error showed up.
I still want to say thanks for your quick reply. It's what makes this forum more interesting than any others.
I figured out in the end what was wrong. Actually, there was nothing wrong with the code, but I guess, that moving the text the regex was looking for, further to the top in the html-file extended the time to find them. At a point it would take too much time to search for the pattern, and thus I got the error message. I found out by moving the text bit-by-bit upwards until the error showed up.
I still want to say thanks for your quick reply. It's what makes this forum more interesting than any others.