Re: strip comments from HTML?
| From: | David T-G | Date: | Thu, 06 May 2004 10:28:51 +0000 |
| Subject: | Re: strip comments from HTML? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185505@lists.php.net to get a copy of this message | ||
Justin --
..and then Justin French said...
%
% Hi,
Hi!
%
% This isn't working:
% $text = preg_replace('/<!--(.*)-->/','',$text);
%
% Can someone advise what characters I need to escape, or whatever to get
% it going?
Well, what do you want it to do? On my system that properly replaces the
entire commented string with nothing. An example which puts something
else there instead:
<?php
$text = "<body>\n<h1>Hi</h1>\n<!-- foo --></body>\n" ;
$text = preg_replace('/<!--(.*)-->/','blah',$text) ;
print "text is .$text.\n";
?>
This yields
text is .<body>
<h1>Hi</h1>
blah</body>
.
as expected.
Note that since you're just replacing the entire comment with '' you
needn't bother with the () around whatever may be in the middle, too.
%
% TIA
%
% ---
% Justin French
% http://indent.com.au
HTH & HAND
:-D
--
David T-G
davidtg@justpickone.org
http://justpickone.org/davidtg/ Shpx gur
Pbzzhavpngvbaf Qrprapl Npg!