2

我在设置 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>

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

4

1 回答 1

3

关闭魔术引号。(此空间特意留空。)

于 2013-02-06T09:07:47.700 回答