Home > Backend Development > PHP Tutorial > Tips to Prevent Chinese Garbled Code on Pure PHP Pages_PHP Tutorial

Tips to Prevent Chinese Garbled Code on Pure PHP Pages_PHP Tutorial

WBOY
Release: 2016-07-13 10:42:54
Original
796 people have browsed it

There are several reasons why Chinese garbled characters appear on PHP pages. One is that the page encoding is not counted. The second is that the encoding is not set in the database. The third is that there is a problem with the apache encoding. Let me introduce two solutions to you. Overall It means that the page encoding is not uniform.

Garbled characters are mostly caused by inconsistencies in encoding methods. There are mainly four inconsistencies that may cause this possibility:

1. Page file encoding method (.html, .php, etc.)

2. Specify the encoding method of the browser in html.head

3. Encoding method for MySql database transmission

4. Apache character set


On a page with only PHP code, when creating a JS pop-up window, if the content of the pop-up window contains Chinese characters, garbled characters may occur,

Solution, one line of code:

Chinese garbled characters on the page

The code is as follows
 代码如下 复制代码

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

Copy code

 代码如下 复制代码


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

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



The database is garbled

The code is as follows Copy code

1. 2.mysql_query('SET NAMES UTF8'); //The next step is to find the data or modify it and add it 4.?> Note: 1. This code must be placed at the top of the file, after ‘ 2. The charset value depends on the entire website code. If it is gb2312, fill in gb2312.

http://www.bkjia.com/PHPjc/633211.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633211.htmlTechArticleThere are several reasons why Chinese garbled characters appear on PHP pages. One is that the page encoding does not count, and the other is that the database does not Set the encoding. The third is that there is a problem with the apache encoding. Let me introduce two solutions to you...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template