Home > php教程 > php手册 > How to solve the problem of Chinese garbled characters in PHP?

How to solve the problem of Chinese garbled characters in PHP?

WBOY
Release: 2016-07-06 14:25:17
Original
1110 people have browsed it

How to solve the problem of Chinese garbled characters in PHP,

How to solve the problem of Chinese garbled characters in PHP

1. Methods to solve the problem of Chinese garbled characters in HTML
1. Add UTF8 encoding (international encoding) in the head tag: UTF-8 is a country-less encoding, which is independent of any language or any language. All can be used.

2. Save the file encoding as UTF-8. Editors such as Notepad or Editplus have the function of selecting encoding when saving.

2. HTML and PHP mixed page solution
In addition to following the operations mentioned in the first method, you also need to add this code at the top of the file:
header("Content-type:text/html;charset=utf-8");
?>

3. The Chinese garbled problem of pure PHP pages (the data is static)
For this, you only need to add the following code at the beginning of the page, and then save the UTF-8 encoded file.
header("Content-type:text/html;charset=utf-8");
?>

4. PHP Mysql Chinese garbled problem
In addition to following the operations mentioned in the third point, you must also add database encoding before querying/modifying/adding your data. Moreover, it is worth noting that the UTF8 here is different from the previous one, there is no horizontal line in the middle.
mysql_query('SET NAMES UTF8');
//The next step is to find the data or modify it, add
?>

5. Correctly display the Chinese name of the uploaded attachment

Find the file config.php in xampp/moodle,
Add $CFG->unicodedb = true; after $CFG->unicodecleanfilename = true;
Then the attachment uploaded by Modeng can be Display Chinese names correctly.

6. When selecting to upload files in the IE browser, garbled characters may be displayed. You can select the file in

lib/editor/htmlarea/coursefiles.php

Add this sentence to the second line: // You can use:set nu to display the line number

@header("Content-Type: text/html; charset=utf-8"); //This is the default selection of utf-8 encoding

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