" in the head tag to set the encoding method; 2. Use "header("Content-type:text/html;charset=utf-8 at the beginning of the PHP code ");" sets the encoding method."/> " in the head tag to set the encoding method; 2. Use "header("Content-type:text/html;charset=utf-8 at the beginning of the PHP code ");" sets the encoding method.">

Home  >  Article  >  Backend Development  >  How to solve the Chinese garbled characters in php html?

How to solve the Chinese garbled characters in php html?

青灯夜游
青灯夜游Original
2020-07-21 16:25:263090browse

How to solve the Chinese garbled characters in php html?

PHP HTML Chinese garbled code problem

1. First, let’s talk about the solution to the HTML Chinese garbled code problem.

Add this sentence in the head tag

<head>  
<meta charset="UTF-8">
</head>

2. HTML and PHP mixed page solution.

<?php  
header("Content-type:text/html;charset=utf-8");
?>

3. PHP Mysql Chinese garbled problem

<?php
   mysql_query(&#39;SET NAMES UTF8&#39;);
?>

UTF-8 encoding is just an encoding. If you don’t want to use utf-8 encoding, you can also use it. For other encodings, just replace UTF-8 with the encoding you want to use. Currently, GB2312 and UTF-8 are mainly used in Chinese website development.

Note: The mysql_query("set names 'encoding'"); encoding is added before the PHP program that needs to perform database operations. The encoding must be consistent with the PHP encoding. If the PHP encoding is GB2312, then the mysql encoding is GB2312, if it is UTF-8, then the mysql encoding is UTF-8, so that there will be no garbled characters when inserting or retrieving data.

Related tutorial recommendations: "PHP Tutorial"

The above is the detailed content of How to solve the Chinese garbled characters in php html?. 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