无法获得htmlpurifier以允许一些tinymce样式通过

时间:2013-02-06 06:48:36

标签: php tinymce htmlpurifier

我在设置htmlPurifier以允许(不过滤掉)接受的css样式时遇到问题。

php代码:

$text = trim(html_entity_decode($text));
require_once("../htmlpurifier/library/HTMLPurifier.auto.php");
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Allowed','p[style],ol[style],li[style],ul[style],b,u,strike,br,span[style]');
$config->set('CSS.AllowedProperties', array('text-decoration' => true,'font-family' => true,'font-size' => true,'text-align' => true,'padding-left' => true,'padding-right' => true,'padding-top' => true,'padding-bottom' => true,'color' => true,'background-color' => true));
$config->set('AutoFormat.RemoveEmpty', true);
$config->set('URI.DisableExternalResources', true);
$purifier = new HTMLPurifier($config);
$text = $purifier->purify("".$text);

输入文字(tinyMCE输出):

<p style=\"text-align: left;\">
    <span style=\"font-family: arial, helvetica, sans-serif; font-size: small;\">
       Lorem ipsum dolor sit amet, conse\'ctetur adipiscing elit. Nunc sit amet ipsum pulvinar elit euismod porta.
    </span>
</p>

实际输出:

<p>
    <span>
        Lorem ipsum dolor sit amet, conse\'ctetur adipiscing elit. Nunc sit amet ipsum pulvinar elit euismod porta.
    </span>
</p>

预期输出:

<p style="text-align:left">
    <span style="font-family:arial, helvetica, sans-serif;font-size:small">
       Lorem ipsum dolor sit amet, conse'ctetur adipiscing elit. Nunc sit amet ipsum pulvinar elit euismod porta.
    </span>
</p>

任何帮助或评论都将不胜感激!!

1 个答案:

答案 0 :(得分:3)

关闭魔术引号。 (这个空间故意留空。)