【发布时间】:2011-08-17 15:49:05
【问题描述】:
我是正则表达式的新手,但需要一个代码来删除所有 html cmets (<!-- here -->),但不能删除 Internet Explorer cmets (<!--[if IE 7]> here <![endif]-->)。我有这个代码:
369
<?php
function stripTags($text, $tags)
{
// replace the internet explorer comments tags so they do not get stripped
$text = preg_replace("<!--[if IE7] (.*?) <![endif]-->", "#?#", $text);
// replace all the normal html comments
$text =preg_replace('/<!--(.|\n)*?-->/g', '', $&text);
// return internet explorer comments tags to their origial place
$text = preg_replace("@#\?#@", "<!--[if IE7] (.*?) <![endif]-->", $text);
return $text;
}
?>
请帮忙。
【问题讨论】:
-
转换 IE 条件 cmets 时,不会将原始值存储在任何地方。
-
你为什么需要它?评论对页面没有任何影响。
-
我已经看到了副本,它正是我所需要的。非常感谢它的伟大。