如何制作多个HTMLpurifier配置?

时间:2015-05-01 16:53:22

标签: php htmlpurifier

我需要针对不同情况的3种不同配置。有时候我需要它来过滤所有内容以及其他形式我需要它来允许某些事情。但是,我注意到任何新的定义,都会对所有其他配置进行更改:(

//this isn't working right
$default_cfg = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($default_cfg);

$purifier_minimal_cfg = HTMLPurifier_Config::createDefault();
$purifier_minimal_cfg->set('HTML.Allowed', 'em,strong,p,br');
$purifier_minimal_cfg->set('AutoFormat.AutoParagraph', true);
$purifier_minimal_html = new HTMLPurifier($purifier_minimal_cfg);

$purifier_featured_html_cfg = HTMLPurifier_Config::createDefault();
$purifier_featured_html_cfg->set('HTML.Allowed', 'a[href],abbr[title],blockquote,br,cite,code,del,div,em,hr,h1,h2,h3,h4,h5,h6,img[alt|src],li,ol,p,s,small,span,strong,table,tbody,td,tfoot,th,thead,tr,ul');
$purifier_featured_html_cfg->set('AutoFormat.AutoParagraph', true);
$purifier_featured_html = new HTMLPurifier($purifier_featured_html_cfg);

if ($purifier_featured_html->purify($html_string) == $purifier->purify($html_string))
echo 'this is bad!';

0 个答案:

没有答案