Home > Backend Development > PHP Tutorial > PHP Warning: json_encode(): Invalid UTF-8 sequence in argument in,该如何处理

PHP Warning: json_encode(): Invalid UTF-8 sequence in argument in,该如何处理

WBOY
Release: 2016-06-13 12:48:04
Original
1382 people have browsed it

PHP Warning: json_encode(): Invalid UTF-8 sequence in argument in
如题,

$vlaue是需要用json_encode()转换,里面包含有中文。执行后全是null,

然后,在网上面找了一些资料,在前面加上下面一句:
$value = mb_check_encoding($value, 'UTF-8') ? $value : utf8_encode($value);

结果不报错了,但是网页打开的却是乱码。

应该如何处理这个情况?

PHP JSON UTF-8 编码 乱码
------解决方案--------------------
用header指定下浏览器编码看看,页头加上:
header("content-type:text/html;charset=utf-8");
------解决方案--------------------
你真够可以的!
string mb_convert_encoding ( string str, string to_encoding [, mixed from_encoding] )

从 from_encoding 到 to_encoding
你没给 from_encoding 那不跟 utf8_encode 一样按字节转换吗?

对于中文,不是 utf-8 就是 gbk 了(台湾地区还有 big5)
怎么着也得 mb_convert_encoding($value, 'UTF-8', 'gbk') 吧
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template