Is There A Uniform Method In Both Php And Js To Convert Unicode Characters?
Is there a uniform method in both PHP and JS to convert unicode characters, so the result would be same on both ends after encoding the unicode string ? Is there any encoding/ deco
Solution 1:
Yes, it's called utf-8. If you encode all documents as utf-8 and store all data as utf-8, you should be in the clear. The problem is that php, per default, expects strings to be latin1, so you need to change a few things (Like send a Content-Type
header etc.)
Solution 2:
I referenced to this question :
How do I convert special UTF-8 chars to their iso-8859-1 equivalent using javascript?
The following functions helped me:
fixed_string = decodeURIComponent(escape(utf_string));utf_string = unescape(encodeURIComponent(original_string));
The escape and unescape functions used for encoding and decoding query strings are defined for ISO characters whereas the newer encodeURIComponent and decodeURIComponent which do the same thing, are defined for UTF-8 characters.
Solution 3:
This is a hack but it works.
PHP
rawurlencode($theString)
JS
decodeURIComponent(theString)
Post a Comment for "Is There A Uniform Method In Both Php And Js To Convert Unicode Characters?"