How to solve the Chinese garbled characters in php html?

青灯夜游
Release: 2023-03-02 19:58:01
Original
3078 people have browsed it

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

2. HTML and PHP mixed page solution.

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

3. PHP Mysql Chinese garbled problem

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

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!