Home > Backend Development > PHP Problem > How to solve the problem of garbled Chinese characters output by PHP?

How to solve the problem of garbled Chinese characters output by PHP?

青灯夜游
Release: 2023-02-26 13:26:01
Original
4175 people have browsed it

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.

How to solve the problem of garbled Chinese characters output by PHP?

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

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

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

For more PHP related knowledge, please visit

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!

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