如何使用 HTML Purifier 使行为正常?

发布于 2024-07-11 08:04:41 字数 789 浏览 4 评论 0原文

我在 PHP 项目中使用 HTML Purifier ,但无法使其与用户输入正常工作。

我让用户使用 WYSIWYG 编辑器 (TinyMCE) 输入 HTML,但是每当用户输入 HTML实体 (不间断空格)它作为这个奇怪的外来字符(Â)保存到数据库中。

然而,问题是,当我使用所见即所得编辑器编辑保存的条目时,它会正确显示为  。 它在显示时也能正常工作,只是在源代码中它显示为真实的空格,而不是不间断的空格字符。

此外,在 MySQL 数据库中,它显示为奇怪的外来字符。

我阅读了有关 Unicode 和 HTML Purifier 的文档,并将我的数据库和网页编码更改为是 UTF-8,但我仍然遇到不间断空格字符未被破坏的问题。 其他 HTML 实体,例如 <&gt;,保存为 <>< /code>,但为什么不是&nbsp;

I am using HTML Purifier in my PHP project and am having trouble getting it to work properly with user input.

I am having users enter in HTML using a WYSIWYG editor (TinyMCE), but whenever a user enters in the HTML entity   (non-breaking space) it gets saved into the database as this weird foreign character (Â).

However, the thing is, when I edit the saved entry using the WYSIWYG editor it gets displayed properly as  . It also functions properly when displayed, only that in the source code it appears as a real space, but not the non-breaking space character.

Also, in the MySQL database it displays as the weird foreign character.

I read the doc about Unicode and HTML Purifier and changed my database and web page encoding to be UTF-8, but I am still having problems with the non-breaking space character not being mangled. The other HTML entities, such as < and >, get saved as < and >, but why not  ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨离汐 2024-07-18 08:04:41

不间断空格不会作为一个奇怪的外来字符保存在数据库中,而是保存为两个字符。 Unicode 不间断空格字符在 UTF-8 中编码为 0xC2 0xA0,在 ISO-8859-1 中看起来像“ ” (即一个奇怪的外来字符后跟一个不间断的空格)。

您可能忘记在数据库连接上执行SET NAMES 'utf8',这会导致 PHP 将其数据作为 ISO-8859-1(默认值)发送到 MySQL。

查看“UTF-8 all the way through...”即可了解使用 PHP 和 MySQL 时如何正确设置 UTF-8。

The non-breaking space isn't being saved in your database as one weird foreign character, it's being saved as two characters. The Unicode non-breaking space character is encoded in UTF-8 as 0xC2 0xA0, which in ISO-8859-1 looks like " " (i.e. a weird foreign character followed by a non-breaking space).

You're probably forgetting to do SET NAMES 'utf8' on your database connection, which causes PHP to send its data to MySQL as ISO-8859-1 (the default).

Have a look at "UTF-8 all the way through…" to see how to properly set up UTF-8 when using PHP and MySQL.

流绪微梦 2024-07-18 08:04:41

它还可以帮助您了解    的替代品,如果您输出任何人类可读的 XML,您可能会需要它;)

It may also help you to know that   is an alternate for   which you will likely require if you ever output any human readable XML ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文