1.html中,设置meta charset='utf8';
2.mysql中创建数据库时,指定为utf8格式。如:create database test character set utf8;
3.php中,在数据库连接函数(mysql_connect())后面,设置names属性为utf8格式(mysql_query("set names utf8"))。
4.在每个页面添加header(
'Content-type: text/html; charset=utf8'
);
5.如果是利用文件导入数据的,在导入的时候指定导入的数据编码。如:
mysql -uroot -p123456 --default-character-set=utf8 test<test1.sql
用户 密码 指定编码为utf8 将test1.sql文件导入test数据库。
总之,要使php,html,数据库编码一致。数据库编码要设置成要求的格式,使用文件导入时要设置导入的格式为要求的格式。
转载于:https://blog.51cto.com/lizude/1247650