我在让HTMLPurifier不过滤标签属性方面遇到了麻烦,但直到现在都没有成功,我快疯了。
$config = HTMLPurifier_Config::createDefault();
$config->set('Core.Encoding', 'UTF-8');
$config->set('Core.CollectErrors', true);
$config->set('HTML.TidyLevel', 'medium');
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional');
$config->set('URI.DisableExternalResources', false);
$config->set('HTML.Allowed', 'table[border|width|style],tbody,tr,td,th,img[style|src|alt],span[style],p[style],ul,ol,li,strong,em,sup,sub');
$PHTML = new HTMLPurifier($config);
echo htmlspecialchars($PHTML->purify($html));
// The input string:
"Some <span style="text-decoration: underline;">cool text</span> <img src="http://someurl.com/images/logo.png" alt="" />.
// The output string:
"Some <span>cool text</span> <img src="%5C" alt="" />.我想要允许在HTML.Allowed选项中定义的指定元素的给定属性。
发布于 2012-05-10 01:15:38
关闭魔术引号。(请注意%5C)
发布于 2015-04-30 13:25:46
我的建议有点晚了,但是我在HTMLPurifier剥离样式属性方面遇到了类似的问题,尽管它们是在HTML.Allowed设置中配置的。
我找到的解决方案要求您还配置CSS.AllowedProperties,它看起来有点像这样:
$config->set('CSS.AllowedProperties', 'text-align,text-decoration,width,height');将其与HTML.Allowed结合使用:
$config->set('HTML.Allowed', 'img[src|alt|style],span[style]');我希望其他人能找到有用的东西,you can read more about CSS.AllowedProperties here。
https://stackoverflow.com/questions/10515111
复制相似问题