note 51321 deleted from function.preg-replace by nlopess
| From: | nlopess@php.net | Date: | Sun, 27 Mar 2005 11:27:56 +0000 |
| Subject: | note 51321 deleted from function.preg-replace by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87053@lists.php.net to get a copy of this message | ||
Note Submitter: hkirsman 2t gmail.com
Reason: bad code
----
preg_replace has some troubles with multi line strings.
Here's a quick fix:
$string = '<!-- SUB: JustASub-->
<h1>test</h1>
works like
CharmeD!
<!-- END SUB: JustASub -->';
$string = str_replace ( array ("\r\n", "\n", "\r"), array
('\r\n', '\n', '\r'), $string );
$string = preg_replace("/<!-- SUB: JustASub-->(.*)<!-- END SUB: JustASub
-->/i", "\\1", $string);
$string = str_replace ( array ('\r\n', '\n', '\r'), array
("\r\n", "\n", "\r"), $string );
echo $string;
Returns:
<h1>test</h1>
works like
CharmeD!