我在PHP中使用正则表达式剥离我的HTML注释。
$html = preg_replace('/<!--(.*)-->/Uis', '', $html);
但是,我不希望正则表达式删除我有条件的IE TAGS
<!--[if lte IE 6]><html class="ie6 no-js">
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->
有没有简单的方法可以做到这一点?
修改 为方便起见,我在此处添加了相关的HTML代码: http://pastebin.com/dPGHHXjU (要么) 在这里:https://regex101.com/r/yS8zM6/1
提前致谢
答案 0 :(得分:0)
答案 1 :(得分:0)
我从另一个帖子得到答案:
$html = preg_replace('~<!--(?!<!)[^\[>].*?-->~s','', $html);
这个正则表达式效果很好。 (但我不确定它的作用)
参考文献:https://stackoverflow.com/a/11337360/1163642(Allen Pestaluky回答的评论)
我在这里添加了一个演示:https://regex101.com/r/yS8zM6/2