开发者

CKEditor charset

开发者 https://www.devze.com 2023-03-19 05:23 出处:网络
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

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 开发者_JS百科character (i.e. é and not &eacute;) 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 &eacute;, 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:

CKEditor charset

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 &eacute; 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.


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 &eacute; set the config for entities_latin to false, as below:

config.entities_latin = false;

Or, you may just want to set following options to false:

config.entities = false;
config.basicEntities = false;


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消