Table of Contents
如何解决PHP中文乱码问题
Home php教程 php手册 如何解决PHP中文乱码问题

如何解决PHP中文乱码问题

Jun 17, 2016 am 08:21 AM

如何解决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编码

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)