PHP page displays Chinese garbled characters
1. HTML page encoding settings
1. Add the code
<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 setting
in the method On the basis of 1, write the first sentence at the front of the php code:
<?php header("Content-type:text/html;charset=utf-8"); ?>
3. Mysql encoding settings
Based on the previous ones, Also add database encoding before querying/modifying/adding your data.
<?php mysql_query('SET NAMES UTF8'); ?>
Note that UTF8 is written here instead of UTF-8! !
Recommended tutorial: PHP video tutorial
The above is the detailed content of PHP displays Chinese garbled characters. For more information, please follow other related articles on the PHP Chinese website!