Skip to main content


Showing posts from July, 2012

Encoding issue with Chinese characters

Was having issue with encoding on PHP (server side) to be printed out on via Javascript (client side).

The problem The Chinese characters were fine when output directly from PHP, became garbled after encoded and decoded on using javascript.
printf('document.write(unescape("%s"));', rawurlencode($data)); 

Solution After Googled for a while I realize the best solution, I think, is to convert the foreign characters to unicode numeric entities. Example:
Numeric CodeHTML Entity CodeResult256&#256Ā
Solution for PHP For PHP there's a simple solution: mb_encode_numericentity(). Luckily the convmap for conversion (excluding HTML character) are in the comment. (As pointed in

function convertToNumericEntities($string) {     $convmap = array(0x80, 0x10ffff, 0, 0xffffff);     return mb_encode_numericentity($string, $convmap, "UTF-8"); }

Solution TinyMCE If you are using TinyMCE, this can be solved by enabling "numeric" fo…