21,873
社区成员




<nav class="xqlj mt15">
<div class="spxq"><img src="1.jpg" width="1200" height="800" alt="" border="0" /><iframe src="http://www.tudou.com/programs/view/html5embed.action?type=1&code=vZ00D1Xubu4&lcode=q711Bs57_Nw&resourceId=0_06_05_99" allowtransparency="true" allowfullscreen="true" allowfullscreeninteractive="true" scrolling="no" border="0" frameborder="0" style="width:1200px;height:500px;"></iframe></div>
</nav>
require('HtmlAttributeFilter.class.php');
$str = '<nav class="xqlj mt15">
<div class="spxq"><img src="1.jpg" width="1200" height="800" alt="" border="0" /><iframe src="http://www.tudou.com/programs/view/html5embed.action?type=1&code=vZ00D1Xubu4&lcode=q711Bs57_Nw&resourceId=0_06_05_99" allowtransparency="true" allowfullscreen="true" allowfullscreeninteractive="true" scrolling="no" border="0" frameborder="0" style="width:1200px;height:500px;"></iframe></div>
</nav>';
$obj = new HtmlAttributeFilter();
// 允许id属性
$obj->setAllow(array('src','alt','border'));
$obj->setException(array());
// img 标签忽略,不过滤任何属性
$obj->setIgnore(array('nav','div','iframe'));
echo 'source str:<br>';
echo htmlspecialchars($str).'<br><br>';
echo 'filter str:<br>';
echo htmlspecialchars($obj->strip($str));