preg_replace删除 IE 注释


preg_replace to remove IE comment

这是我的字符串:

aaa <!--[if (gt IE 9)|!(IE)]><!--> <html lang='"en'"> <!--<![endif]--> bbb

这就是我想要的:

aaa  <html lang='"en'">  bbb

这就是我得到的:

aaa    bbb

这里出了什么问题?

<?php
$content="aaa <!--[if (gt IE 9)|!(IE)]><!--> <html lang='"en'"> <!--<![endif]--> bbb";
$tagOpen="<!--[if (gt IE 9)|!(IE)]><!-->";
$tagClose="<!--<![endif]-->";
$condition='/'.preg_quote($tagOpen).'.*?'.preg_quote($tagClose).'/i';
$content=preg_replace($condition, '$1', $content);
echo htmlentities($content);

链接: http://3v4l.org/TrO1U

您没有创建捕获组。尝试:

$condition='/'.preg_quote($tagOpen).'(.*?)'.preg_quote($tagClose).'/i';