Home > php教程 > php手册 > body text

php 保存到mysql数据库中的中文乱码,

WBOY
Release: 2016-06-13 08:39:04
Original
991 people have browsed it

php 保存到mysql数据库中的中文乱码,

近期又php项目,乱码是个头痛的问题

解决方法:

1,php 文件中 添加 header(“Content-Type: text/html; charset=utf-8");

2,需要做数据库操作的php程序前加mysql_query("set names '编码'");,编码和php编码一致,如果php编码是gb2312那mysql编码就是gb2312,如果是utf-8那

mysql编码就是 utf8,这样插入或检索数据时就不会出现乱码了

mysql_query("set names 'utf8'") 或者mysqli_query("set names 'utf8'");

需要注意的是红色标示的地方 是utf8 不是utf-8;

3,使用的html文件的编码也要一直,一般使用utf-8;

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!