Home  >  Article  >  Backend Development  >  新手请教php乱码问题。

新手请教php乱码问题。

WBOY
WBOYOriginal
2016-06-23 14:14:35992browse

PHP 乱码 UTF-8

我的mysql数据库,数据库,数据表,字段,连接校对,都是UTF-8编码。
reg01.php提交中文数据到reg02.php,echo SQL语句和存入到数据库里,都是乱码呢?
reg01.php有

图示如下:
1.mysql数据库,和数据库连接校对都是UTF-8编码


2.数据库,字段都是UTF-8编码



3.echo sql语句和存入数据库都是乱码



什么原因呢?好烦这个问题。

回复讨论(解决方案)

从你最后一张贴图上看,你是在 gbk 编码的界面中输出 utf-8 编码的内容

不明白。我的reg02.php,和reg01.php都是utf-8编码

在eclipse的编码设置是这个编码的。

我的mysql数据库,数据库,数据表,字段,连接校对,都是UTF-8编码。
reg01.php提交中文数据到reg02.php,echo SQL语句和存入到数据库里,都是乱码呢?
reg01.php有

图示如下:
1.mysql数据库,和数据库连接校对都是UTF-8编码


2.数据库,字段都是UTF-8编码



3.echo sql语句和存入数据库都是乱码



什么原因呢?好烦这个问题。

utf8编码的程序里直接echo字符串时,记得要在echo前加上

header("Content-Type: text/html; charset=utf-8");
或者在要输出的字符串前加上
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

echo输出没有乱码了,但存到数据库里面的,还是乱码。

也加上了mysql_set_charset("utf-8");
还是乱码,晕菜了

插入sql前加上:mysql_query("set names utf8"); 应该就可以了

Statement:
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