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

PHP页面中文乱码分析

WBOY
Release: 2016-06-06 20:27:01
Original
1156 people have browsed it

php出现出现乱码的原因:页面文件的编码方式(.html,.php等)、html.head中指定浏览器的编码方式、MySql数据库传输的编码方式、Apache字符集。

PHP页面中文乱码出现的原因有几种,一种是页面编码不统计一,二是数据库未设置编码,三是apache编码有问题,下面我来给大家介绍两种解决办法,总体来讲就是页面编码不统一了。
出现乱码大部分是由于编码方式的不一致导致的,其中主要有四个地方不一致就可能存在这个可能:
1、页面文件的编码方式(.html,.php等)
2、html.head中指定浏览器的编码方式
3、MySql数据库传输的编码方式
4、Apache字符集

在只有PHP代码的页面,做JS弹窗的时候,如果弹窗内容含有中文,可能会出现乱码的问题,
解决办法,一行代码:
页面中文乱码

复制代码 代码如下:


header(“Content-Type: text/html; charset=utf-8");


数据库是乱码

复制代码 代码如下:


.mysql_query('SET NAMES UTF8'); 
//接下来的就是查出数据或者修改,,增加咯  
?>


注意:
1、此代码必须放在文件最上面, ‘2、charset值要看整个网站编码,如果是gb2312,则填gb2312。
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!