Using this regex expression:
preg_replace( '/<!--(?!<!)[^\[>].*?-->/', '', $output )
I'm able to remove all HTML comments from my page except for anything that looks like this:
<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->
How can I modify this to also exclude HTML comments which include a unique phrase, such as "batcache"?
So, an HTML comment this:
<!--
generated 37 seconds ago
generated in 0.978 seconds
served from batcache in 0.004 seconds
expires in 263 seconds
-->
Won't be removed.
This code seems to do the trick:
preg_replace( '/<!--([\s\S]*?)-->/', function( $c ) { return ( strpos( $c[1], '<![' ) !== false || strpos( $c[1], 'batcache' ) !== false ) ? $c[0] : ''; }, $output )