php如何过滤前端传过来的html代码允许指定标签?
比如html代码中只允许p img 和pre标签能保留,其他全部过滤掉。
网友回复
使用HTMLPurifier库来实现,代码如下:
<?php require('../lib/php/HTMLPurifier/HTMLPurifier.auto.php'); $dirty_html = <<<EOF <h1><a href="http://www.baidu.com">Hello</a> <script>alert("world");</script> EOF; $config = \HTMLPurifier_Config::createDefault(); //$config->set('HTML.Allowed', '');//过滤掉所有的HTML标签 $conf...
点击查看剩余70%