正则表达式,清除HTML标签,但要保留 <BR>和<IMG>标签,其他的清除
1个回答
展开全部
function CleanHTML($str) {
$preg = "/<(.[^(br|img)][^>]*)>/i" ;
$str = preg_replace($preg, "", $str);
return $str;
}
$s = "AAAAAA<a href=\"\">BBB</a>cccc<br />c<b>C</b> <img src='123.gif' /> <span>date</span>kkk";
echo CleanHTML($s);
$preg = "/<(.[^(br|img)][^>]*)>/i" ;
$str = preg_replace($preg, "", $str);
return $str;
}
$s = "AAAAAA<a href=\"\">BBB</a>cccc<br />c<b>C</b> <img src='123.gif' /> <span>date</span>kkk";
echo CleanHTML($s);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询