Home  >  Article  >  Backend Development  >  Garbled characters appear when php reads mysql Chinese data_PHP tutorial

Garbled characters appear when php reads mysql Chinese data_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:15:331114browse

1. The encoding type of the PHP page language itself is inappropriate. At this time, the Chinese you write directly in the script will definitely be garbled, let alone the database;
Solution: Select 'UTF8' or ' gb2312', so that the customer's browser will automatically select and display the correct Chinese display. Note: 'UTF8' or 'gb2312' can display Chinese correctly.
2. The encoding type in the database MySQL is incorrect.
Solution: When creating the database, select 'UTF8' for the MySQL character set and utf8_general_ci for the MySQL connection proofreading. There will definitely be no problem with the database created in this way for storing Chinese.
Otherwise, your Chinese will first be stored in MySQL Garbled code, don't expect it to display correctly in your PHP page.
3. It is related to the usual script editing environment. For example, some content is written by myself in Word, some is written in Notepad, and some is written using text editors such as EditPlus and UltraPlus. Sometimes I write Chinese directly in DW.
Solution: Try to use the same editor. If you are copying existing content, it is recommended to use the encoding conversion function in ultraplus to convert it to utf8 or gb2312.
It doesn’t matter what type it is converted into. The key is that the encoding in your PHP WEB application must be consistent.
4. When accessing MySQL programmatically, it is recommended to add a line of code: mysql_query("SET NAMES 'GBK'");

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440186.htmlTechArticle1. The encoding type of the PHP page language itself is not suitable. At this time, the Chinese you write directly in the script must be It's garbled code, not to mention the database; Solution: Choose 'UTF8' or 'gb2312',...
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