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

PHP displays Chinese garbled characters

王林
Release: 2023-02-25 15:18:01
Original
5022 people have browsed it

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>
Copy after login

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

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;);     
?>
Copy after login

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!

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