in the head tag; 2. When saving the file Set encoding UTF-8."/> in the head tag; 2. When saving the file Set encoding UTF-8.">

Home  >  Article  >  Backend Development  >  PHP displays Chinese garbled characters

PHP displays Chinese garbled characters

王林
王林Original
2019-09-29 11:55:094942browse

PHP displays Chinese garbled characters

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(&#39;SET NAMES UTF8&#39;);     
?>

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!

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