gpt4 book ai didi

php - HTML 净化器转换 & -> &

转载 作者:行者123 更新时间:2023-12-04 17:55:52 24 4
gpt4 key购买 nike

我在我的文本字段中使用 HTML Purifier(Yii2)。

我需要在原件中保存“&”,但净化器转换为“&”;

我不想用 str_replace净化器后。

你能帮我配置吗?

我的配置:

['name'],
'filter',
'filter' => function($value) {
return HtmlPurifier::process($value, [
'HTML.SafeObject' => true,
'HTML.SafeEmbed' => true,
'Core.EscapeNonASCIICharacters' => true,
'Core.Encoding' => 'UTF-8'
]);
}

更新:

文本示例,我想要净化的内容:“公司名称和公司”

最佳答案

您在评论中提到您在将信息输入数据库之前要进行净化。

我建议您从架构的角度重新考虑这一点,因为它有几个不足之处,例如您丢失了原始用户输入(您以后可能出于任何原因想要对其进行分析),一旦您的数据库变得不那么有用了您想对数据做其他事情,并且您当前版本的 HTML Purifier(可能与安全相关)中的错误不会被解决。您可以查看有关 重要性的更多信息为上下文转义/清理 this answer .

也就是说,您的问题之前已在 HTML Purifier 论坛上讨论过:Do not escape ampersand .该线程讨论了为什么难以治疗 &以不同的方式保持安全,并且基本上“建议”不要使用 HTML Purifier,这当然不能解决您的问题。

尽管如此,如果您被迫将纯化的 HTML 存储在数据库中,那么该线程中有一些建议和想法可能会对您有所帮助:

Perhaps a more useful response would be: store the raw, user submitted data (without running HTML Purifier on it) in the database, and run search queries on that. However, store in the database as well a cached version of the HTML Purified version.



或者(这里以 < 为例):

No such boolean flag exists, and it would be reasonably tricky to implement safely (you'd want to do something silly like convert literal < and friends to some unforgeable piece of text and then convert &lt; to the literal version.)



但后者不是一种稳健的方法,而前者是一种不必要的冗余。

关于php - HTML 净化器转换 & -> &,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40463606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com