Home  >  Article  >  Backend Development  >  What should I do if php Chinese returns garbled characters?

What should I do if php Chinese returns garbled characters?

藏色散人
藏色散人Original
2020-08-29 10:26:094094browse

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>

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");  
?>

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;);     
?>

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!

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