0
这是我的字符串:preg_replace函数删除IE评论
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);
''。*?''应该是''(。*?)''(否则,不是'$ 1'子模式)。 – Wrikken