note 79830 added to function.ereg-replace
| From: | eduardo at bragatto dot com | Date: | Fri, 14 Dec 2007 13:55:47 +0000 |
| Subject: | note 79830 added to function.ereg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133454@lists.php.net to get a copy of this message | ||
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 -->".
----
Server IP: 208.69.120.35
Probable Submitter: 72.89.211.6
----
Manual Page -- http://www.php.net/manual/en/function.ereg-replace.php
Edit -- https://master.php.net/note/edit/79830
Del: integrated -- https://master.php.net/note/delete/79830/integrated
Del: useless -- https://master.php.net/note/delete/79830/useless
Del: bad code -- https://master.php.net/note/delete/79830/bad+code
Del: spam -- https://master.php.net/note/delete/79830/spam
Del: non-english -- https://master.php.net/note/delete/79830/non-english
Del: in docs -- https://master.php.net/note/delete/79830/in+docs
Del: other reasons-- https://master.php.net/note/delete/79830
Reject -- https://master.php.net/note/reject/79830
Search -- https://master.php.net/manage/user-notes.php