重音符号打破json_en code()在PHP [英] accented characters breaks json_encode() in PHP

查看:142
本文介绍了重音符号打破json_en code()在PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组其中的关键之一,包含了一些HTML code。我json_encoding这个数组返回。我最近注意到,json_en code()返回'零'如果HTML包含特殊字符(比如:一个MEHvirága)。

I have an array which one of the keys contains some HTML code. I am json_encoding this array for returning. I have recently noticed that json_encode() returns 'null' if the html contains special characters (ie: A méh virága).

如何才能让json_en code()不返回'空'如有特殊重音符号有哪些?

How can I get json_encode() not to return 'null' if special accented characters are available?

推荐答案

json_en code()假设文本是UTF-8编码。如果输入的样子畸形的UTF-8,它返回。获得唯一的办法 json_en code()来的工作是给它输入UTF-8(你或许应该使用反正)。

json_encode() assumes that text is in UTF-8 encoding. If the input looks like malformed UTF-8, it returns null. The only way to get json_encode() to work is to give it input in UTF-8 (which you should probably be using anyway).

此外,由于Zathrus作者说在注释中,C本身实际的PHP源$ C ​​$也许应该也可以在UTF-8编码,以prevent微妙的错误。

And, as Zathrus Writer says in a comment, the actual PHP source code itself should probably also be in UTF-8 encoding, to prevent subtle bugs.

这篇关于重音符号打破json_en code()在PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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