test'; The above will ...">

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!

-1


source to share


3 answers


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.



+2


source


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.

+2


source


0


source







All Articles