问题
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:
No, that’s JSON. JSON encoders are free to copy characters as-is (except for doublequote, backslash, or control characters) or to encode them using the \uxxxx
notation. So even while the above is not beautiful, it’s valid JSON and will ensure that the string will be decoded correctly.
回答2:
The title
attribute value is not treated as JavaScript. Use json_encode
only for converting a PHP type into a JavaScript/JSON expression.
Try this instead:
echo '<a title="按时间先后进行排序">test</a>';
But you would need to send your document with the the same encoding as your title text.
回答3:
have you tried this: http://us.php.net/manual/en/function.json-encode.php#74878
来源:https://stackoverflow.com/questions/1531881/how-to-make-jscon-encode-work-with-multibyte-characters