Posts

Showing posts with the label Encoding

Encoding issue with Chinese characters

Image
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 Code HTML Entity Code Result 256 &#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 http://stackoverflow.com/a/3116893 ) function convertToNumericEntities($string) {     $convmap = array(0x80, 0x10ffff, 0, 0xffffff);     return mb_encode_numericentity($string, $convmap, "UTF-8"); } Solution TinyMCE If you are using TinyMCE , t...

How to get Eclipse source files unix compatible.

Unlike Unix, which uses a bare line feed (\n) to denote the end of a line, Windows uses a carriage return followed by a line feed (\r\n). When present in an interpreter specification, this extra carriage return is a problem, as the robot reads #!/usr/bin/python\r\n, for example, and can’t find the interpreter /usr/bin/python\r ! If your program has an interpreter specification, make sure you convert it to Unix text before submitting. Alternatively, put your code in a file called (for example) hoppity.py and also send a file called hoppity with the contents. [ source ] Discovered the unpleasant Windows new line characters in my source code and wanted to remove the extra \r carriage return at the end of file in order to submit the source code to Facebook Puzzlebot . Below are the steps to make your source code Puzzlebot compatible. To set file encoding to UTF-8 and line-endings for new files to Unix, so that text files are saved in a format that is not specific to the Wind...