如何使jscon_encode使用多字节字符? [英] How to make jscon_encode work with multibyte characters?

查看:122
本文介绍了如何使jscon_encode使用多字节字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

echo '<a title=' .json_encode("按时间先后进行排序") . '>test</a>';

上面的代码会生成类似"\ u6309 \ u65f6 \ u95f4 \ u5148 \ u540e \ u8fdb \ u884c \ u6392 \ u5e8f"的东西!

The above will generate something like "\u6309\u65f6\u95f4\u5148\u540e\u8fdb\u884c\u6392\u5e8f" and it's a mess!

推荐答案

title属性值未视为JavaScript. json_encode仅用于将PHP类型转换为JavaScript/JSON表达式.

The title attribute value is not treated as JavaScript. Use json_encode only for converting a PHP type into a JavaScript/JSON expression.

尝试以下方法:

echo '<a title="按时间先后进行排序">test</a>';

但是您需要使用与标题文本相同的编码发送文档.

But you would need to send your document with the the same encoding as your title text.

这篇关于如何使jscon_encode使用多字节字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆