How to delete html comments in php

advertisements

I am trying to remove any comments embedded with the html file

$data= file_get_contents($stream); <br>
$data = preg_replace('<!--*-->', '', $data); <br>
echo $data;

I am still ending up with all the comments < !- bla bla bla -->
What am I doing wrong?


The below regex will remove HTML comments, but will keep conditional comments.

<!--(?!<!)[^\[>].*?-->