开发者

CKEditor / Ajax special characters encoding / decoding not working

I'm using CKEditor, and typing in some text with special characters: "Bâtisseurs passionnés", note french special characters. I then use javascript escape() to get the input and send it via AJAX/JSON to the PHP server script.

On the PHP side of things, the log output looks like the following before and after using urldecode(), it appears to convert the

tag parts but the special characters only show up as '?' and stored as such into the database. Is there another call I should be using? Or are special characters not included for urldecode?

$json = json_decode($data);
error_log("URLDecode: before: " . $data);
error_log("URLDecode: after: " . urldecode($data));

and the output looks like

开发者_StackOverflowURLDecode: before: %3Cp%3E%0A%09B%E2tisseurs%20passionn%E9s%3C/p%3E%0A
URLDecode: after: <p>
    B?tisseurs passionn?s</p>


escape isn't a match pair for php's urldecode.
Use encodeURIComponent in javascript.

escape and unescape Functions
The escape and unescape functions do not work properly for non-ASCII characters and have been deprecated. In JavaScript 1.5 and later, use encodeURI, decodeURI, encodeURIComponent, and decodeURIComponent.

MDC:functions

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜