Home  >  Article  >  Backend Development  >  Analysis of Chinese garbled characters in PHP pages_PHP tutorial

Analysis of Chinese garbled characters in PHP pages_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:25:45741browse

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 four main inconsistencies that may cause this possibility:
1. Encoding method of page files (.html, .php, etc.)
2. The encoding method of the browser specified in html.head
3. The encoding method of 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.
The solution is a line of code:
Chinese garbled characters on the page

Copy code The code is as follows:

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

The database is garbled
Copy code The code is as follows:

.mysql_query ('SET NAMES UTF8');
//The next step is to find the data or modify it and add it
?>

Note:
1. This code must Place it at the top of the file, after '2. The charset value depends on the entire website code. If it is gb2312, fill in gb2312.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824967.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...
Statement:
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