CKEditor 字符集
我更新了我的网络应用程序以使用 UTF-8 而不是 ANSI。
我采取了以下措施来定义字符集:
mysql_set_charset("utf8"); // PHP
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> // HTML
utf8_general_ci // In MySQL
我还编辑了 CKEditor 配置以删除 htmlentities,因为我需要 MySQL 的正确字符(即 é
而不是 é
)全文搜索。
config.entities = false;
config.entities_latin = false;
在数据库(phpMyAdmin 视图)和普通文本字段输出(HTML、 或
然而,CKEditor 在编码方面存在一些问题。请参阅附图,了解从数据库中获取的同一字段,显示在文本区域中,然后显示在由 CKEditor 替换的文本区域中:
这似乎在 CKEditor JavaScript 代码中(可能是固定字符集),但我找不到它在配置中。同样,由于 é
在正常 HTML 中正确显示(真正的 UTF-8 é
,而不是 é
也不是 é< /code>),我很确定这不是 PHP/MySQL 查询错误(但我可能是错的)。
编辑:这似乎是应用 htmlentities
的症状,默认情况下,它在 UTF-8 文本上以 Latin-1 编码。可以使用 htmlspecialchars
或指定字符集(“utf-8”),但我不知道在 CKEditor 中在哪里修改它。
I updated my web app to use UTF-8 instead of ANSI.
I did the following measures to define charset:
mysql_set_charset("utf8"); // PHP
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> // HTML
utf8_general_ci // In MySQL
I also edited the CKEditor config to remove htmlentities because I need the correct character (i.e. é
and not é
) for MySQL fulltext search.
config.entities = false;
config.entities_latin = false;
In the database (phpMyAdmin view) and on normal text fields output (HTML, <input>
or <textarea>
), everything looks fine (I see é
, not é
, not é
, yay).
However, CKEditor has some trouble with the encoding. See attached image for the same field taken from the database, displayed in a textarea, then in a textarea repalced by CKEditor:
This seems to be in the CKEditor JavaScript code (probably a fixed charset), but I can't find it in the config. Again, since the é
displays correctly in normal HTML (real UTF-8 é
, not é
nor é
), I'm quite sure it's not the PHP/MySQL query that's wrong (but I might be mistaken).
EDIT: This seems like a symptom of applying htmlentities
, which by default is encoded in Latin-1, on UTF-8 text. There is either a possibility of using htmlspecialchars
or to specify the charset ("utf-8"), but I don't know where to modify that in CKEditor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该线程似乎有点过时,但回答它可以帮助任何寻求回应的人。
允许
CKEditor
将字符é
处理为é
而不是é
;将entities_latin
的配置设置为false
,如下所示:或者,您可能只想将以下选项设置为 false:
This thread seems bit dated but answering it to help anyone looking for a response.
To allow
CKEditor
to process the characteré
asé
and noté
; set the config forentities_latin
tofalse
, as below:Or, you may just want to set following options to false:
错误的是我的方法,而不是 CKEditor 的方法。查找了错误的文件并错过了
htmlspecialchars
上的 UTF-8 编码。It was my approach that was wrong, not CKEditor's. Was looking in the wrong file and missed the UTF-8 encoding on a
htmlspecialchars
.您还可以在数据库连接中使用:
$connection->query("SET NAMES 'utf8'");
并记住将数据库和/或表排序规则设置为utf8...我更喜欢
utf8_general_ci
You can also use in your database connection:
$connection->query("SET NAMES 'utf8'");
And remember to set db, and/or table Collation to utf8... I prefer
utf8_general_ci