When writing code in PHP, sometimes you may find that the Chinese output has garbled characters. So, how should we solve this kind of garbled PHP output? Let me introduce to you the solution below.
The problem with php outputting garbled Chinese characters is nothing more than the following aspects;
1. HTML page encoding settings
1. Add this sentence
<head> <meta http-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
On the basis of the previous ones, you must also add database encoding before querying/modifying/adding your data.<?php mysql_query('SET NAMES UTF8'); ?>
PHP Chinese website!
The above is the detailed content of How to solve the problem of garbled Chinese characters output by PHP?. For more information, please follow other related articles on the PHP Chinese website!