1.把html元素全部去掉,或者保留某几个html标签
复制代码 代码如下:
结果为(去掉了注释):
test paragraph. other text
test paragraph.
other text2.相反,只去掉某一个html标签
复制代码 代码如下:
') !== false ? explode('>', str_replace(' if(end($tags) == '') array_pop($tags);
}
foreach($tags as $tag) {
if ($stripcontent)
$content = '(.+'.$tag.'[^>]*>|)';
$str = preg_replace('#?'.$tag.'[^>]*>'.$content.'#is', '', $str);
}
return $str;
}$str = 'red text';
$tags = 'font';
$a = strip_only($str, $tags); // red text
$b = strip_only($str, $tags, true); // text
?>
http://www.bkjia.com/phpjc/621724.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/621724.htmltecharticle1.把html元素全部去掉,或者保留某几个html标签 复制代码 代码如下: ?php $text = 'ptest paragraph./p!-- comment -- a href=#fragmentother text/a'; echo strip_...