How do I get jscon_encode to work with multibyte characters?
echo '<a title=' .json_encode("ζζΆι΄ε
εθΏθ‘ζεΊ") . '>test</a>';
The above will generate something like "\ u6309 \ u65f6 \ u95f4 \ u5148 \ u540e \ u8fdb \ u884c \ u6392 \ u5e8f" and it's a mess!
No, it's JSON. JSON encoders can copy characters as-is (excluding doubles, backslashes, or control characters) or encode them using a notation \uxxxx
. So even though the above is not pretty, its valid JSON and ensures the string is decoded correctly.
The attribute value is title
not considered JavaScript. Use json_encode
only to convert PHP type to JavaScript / JSON expression.
Try this instead:
echo '<a title="ζζΆι΄ε
εθΏθ‘ζεΊ">test</a>';
But you need to send your document with the same encoding as the header text.
Have you tried this: http://us.php.net/manual/en/function.json-encode.php#74878