当前位置:Gxlcms > PHP教程 > 从数据库创建到php读取json_encode中文正确显示phpjsonphpjsonencodejsonencode中文

从数据库创建到php读取json_encode中文正确显示phpjsonphpjsonencodejsonencode中文

时间:2021-07-01 10:21:17 帮助过:24人阅读

共识:1.首先应该确定,中文也是应该用varchar来存储的
2.测试使用MySQL语句查看字符集

show variables like "%char%";
show variables like "collatio%";

如果查看后有编码不统一(中文应用gbk或utf8支持)的地方,可以特定地修改某一项的值,例如:

SET character_set_client='utf8';

1.创建数据库

CREATEDATABASE databasename
CHARACTERSET'utf8'COLLATE'utf8_general_ci';

2.创建表

  CREATE TABLE industry_name (
                       ...
                      ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

这里与普通建表唯一不同的地方就是最后的一句话

测试看是否utf8统一

——————至此就可以在mysql查看的时候显示中文了—————-

json decode php,urlencode,eval,php json_encode,json encode中文,iconv,json_encode中文,urldecode,ch_json_encode,encode,arrayrecursive,json_unescaped_unicode,php json,php json encode,json encode中文

然后想办法在php中得到中文
1.在代码前段写上

header("Content-Type: text/html;charset=utf8");

2.在connection建立以后写上

mysqli_query($connection, "SET NAMES utf8");

————至此就可以在PHP页面中显示中文了————-

最后,如果需要用到json_encode,那么需要注意最后一点

$json_string = json_encode($result_row, JSON_UNESCAPED_UNICODE);

即在普通的json_encode中多加入一个参数,至此就全部完成啦~

json decode php,urlencode,eval,php json_encode,json encode中文,iconv,json_encode中文,urldecode,ch_json_encode,encode,arrayrecursive,json_unescaped_unicode,php json,php json encode,json encode中文

参考文章:
(转)Mysql中文乱码问题完美解决方案(包括建库、导入数据、网页)
彻底解决mysql中文乱码的办法

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了从数据库创建到php读取json_encode中文正确显示,包括了json_encode方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 人气教程排行