如何解决PHP中文乱码问题
一、解决HTML中中文乱码问题方法
1、在head标签里面加入UTF8编码(国际化编码):UTF-8是没有国家的编码,也就是独立于任何一种语言,任何语言都可以使用的。
2、将文件的编码存为UTF-8。记事本或Editplus等编辑器都有保存时选择编码的功能。
二、HTML和PHP混合的页面解决方案
除了按照第一个方法所说的操作之外,还需要在文件的最上面加入这句代码:
header("Content-type:text/html;charset=utf-8");
?>
三、纯PHP页面的中文乱码问题(数据是静态的)
这个只需要在页面的开始处加入下面代码,然后保存UTF-8编码的文件即可。
header("Content-type:text/html;charset=utf-8");
?>
四、PHP+Mysql中文乱码问题
这个除了按照第三点所说的操作之外,还要在你的数据查询/修改/增加之前加入数据库编码。而且,值得注意的是,这里的UTF8和之前的不一样,中间是没有横线的。
mysql_query('SET NAMES UTF8');
//接下来的就是查出数据或者修改,增加
?>
五、正确显示上传的附件中文名
找到xampp/moodle中的文件config.php,
在$CFG->unicodedb = true;后加入$CFG->unicodecleanfilename = true;
即可使摩灯上传的附件可以正确显示中文名。
六、在ie浏览器中选择上传文件时还可能显示乱码等,可以在
lib/editor/htmlarea/coursefiles.php
第二行加上这样一句:// 可以用:set nu显示行号
@header("Content-Type: text/html; charset=utf-8"); //这个是默认选择utf-8编码

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment
