php网页乱码问题

网页乱码问题归根结底还是数据库编码以及网页编码不统一造成的,可以在这几个地方检查一下:

1.数据库保存时编码检查是否是utf-8。

2.网页编码

a.

1 header("Content-type: text/html; charset=utf-8");   //写在php代码块中

b.

1 $conn = new mysqli("localhost", "root", "123456", "apple");
2 $conn->set_charset("utf8");    //注意字符串是"utf8",不是"utf-8",数据库连接编码格式。也可以这么写$conn->query("set names utf8");
3 $sql="select * from product_info WHERE product_id=".$product_id;

 

c.

1    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />      //写在html代码块<head>标签中

 

posted @ 2016-08-02 09:57  DespicableMe  阅读(215)  评论(0编辑  收藏  举报