Usuwanie komentarzy HTML z warunkami PHP, ale pozostawiając
Obecnie używam PHP i wyrażenia regularnego, aby usunąć wszystkie komentarze HTML ze strony. Skrypt działa dobrze ... trochę za dobrze. Usuwa wszystkie komentarze, w tym moje komentarze warunkowe w. Oto co mam:
<?php
function callback($buffer)
{
return preg_replace('/<!--(.|\s)*?-->/', '', $buffer);
}
ob_start("callback");
?>
... HTML source goes here ...
<?php ob_end_flush(); ?>
Ponieważ moje wyrażenie regularne nie jest zbyt gorące, mam problem z ustaleniem, jak zmodyfikować wzór, aby wykluczyć komentarze warunkowe, takie jak:
<!--[if !IE]><!-->
<link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen" />
<!-- <![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" href="/css/ie7.css" type="text/css" media="screen" />
<![endif]-->
<!--[if IE 6]>
<link rel="stylesheet" href="/css/ie6.css" type="text/css" media="screen" />
<![endif]-->
Twoje zdrowie