What should I do if php Chinese returns garbled characters?

藏色散人
Release: 2023-03-05 12:50:01
Original
4148 people have browsed it

Solution to the garbled code returned by php in Chinese: 1. Add the code "charset=UTF-8" in the head tag; 2. Set the encoding to "UTF-8" when saving the file; 3. Set the PHP encoding to "charset=utf-8"; 4. Mysql encoding is set to "NAMES UTF8".

What should I do if php Chinese returns garbled characters?

Recommended: "PHP Video Tutorial"

php output Chinese garbled code problem

Many beginners may encounter the problem of outputting garbled Chinese characters when they first start learning PHP;

The methods to solve this problem are nothing more than the following:

1 , HTML page encoding settings

1. Add this sentence

<head>  
<metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/>  
</head>
Copy after login

in the head tag 2. Set the encoding to UTF-8 when saving the file.

2. PHP encoding settings

Based on method one, write

<?php  
header("Content-type:text/html;charset=utf-8");  
?>
Copy after login

at the very beginning of the PHP code, i.e. the first sentence. 3. Mysql encoding settings

Based on the previous ones, you also need to add database coding before querying/modifying/adding your data.

<?php  
mysql_query(&#39;SET NAMES UTF8&#39;);     
?>
Copy after login

Note that UTF8 is written here instead of UTF-8! ! !

Following the above method settings should be able to solve the problem of outputting Chinese garbled characters.

The above is the detailed content of What should I do if php Chinese returns garbled characters?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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