note 79830 deleted from function.ereg-replace by bjori
| From: | bjori@php.net | Date: | Fri, 14 Dec 2007 19:58:50 +0000 |
| Subject: | note 79830 deleted from function.ereg-replace by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133475@lists.php.net to get a copy of this message | ||
Note Submitter: eduardo at nospam dot bragatto dot com
----
If you have a file with:
<!-- BEGIN COMMENT -->
Test1
<!-- END COMMENT -->
<!-- BEGIN COMMENT -->
Test2
<!-- END COMMENT -->
And you do:
<?php
$pattern='<!-- BEGIN COMMENT -->.*Test1.*<!-- END COMMENT -->';
$replace='TEST!';
$contents=file_get_contents(yourfile here);
$contents=ereg_replace($pattern, $replace, $contents);
echo $contents;
?>
Your result will be:
TEST!
Instead of:
TEST!
<!-- BEGIN COMMENT -->
Test2
<!-- END COMMENT -->
ereg_replace does not stop at the first occurrence of "<!-- END COMMENT -->" (when
you'd think the pattern already matches) and keeps selecting what to replace until it finds the
very last "<!-- END COMMENT -->".