Chinese garbled characters saved in php to mysql database, _PHP tutorial

WBOY
Release: 2016-07-12 08:51:40
Original
968 people have browsed it

The Chinese garbled characters saved by php to the mysql database,

Recently, there is a php project, garbled characters are a headache problem

Solution:

1. Add header("Content-Type: text/html; charset=utf-8");

2. Add mysql_query("set names 'encoding'"); before the PHP program that needs to perform database operations. The encoding is consistent with the PHP encoding. If the PHP encoding is gb2312, then the mysql encoding is gb2312. If it is utf-8, then

MySQL encoding is utf8, so that there will be no garbled characters when inserting or retrieving data

mysql_query("set names 'utf8'") or mysqli_query("set names 'utf8'");

It should be noted that the areas marked in red are utf8, not utf-8;

3. The encoding of the html file used must also be consistent, generally using utf-8;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1128382.htmlTechArticlephp Chinese garbled characters saved to the mysql database. In a recent php project, garbled characters are a headache. Solution: 1 , add header(Content-Type: text/html; charset=utf-8")...
in the php file
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