I am looking for a subroutine to remove HTML/XML comments from data. The best thing I have come up with is the following, but I would prefer to avoid the __LINEFEED__ token if possible. Any suggestions? Any cases this might not account for?
sub removeComments( $ )
{
my ${data} = shift( @{_} );
${data} =~ s#[\r]?[\n]#__LINEFEED__#g;
${data} =~ s#<!--(.*?)-->##g;
${data} =~ s#__LINEFEED__#${/}#g;
return( ${data} );
}
Something that wouldn't remove JavaScript would also be great, for instance this case:
<script><!--
alert( 'alert' );
//--></script>
Edited by JimmyFat on 05/06/04 10:21 AM (server time).