我有一个数组其中的关键之一,包含了一些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.
相关推荐
最新文章