主要作用:过滤一些可执行的代码,避免网站受到xss攻击。
可用在保存数据库&页面展示。
$html = <<<eof
<script>alert('我弹!');</script>
<div>
<p>text...</p>
</div>
eof;
$p = new CHtmlPurifier();
$p->options = array('URI.AllowedSchemes' => array(
'http' => true,
'https' => true,
));
$text = $p->purify($html);
echo $text;
output:
<div>
<p>text...</p>
</div