Home >Backend Development >PHP Problem >What to do if php uploads Chinese data with garbled characters

What to do if php uploads Chinese data with garbled characters

藏色散人
藏色散人Original
2022-10-25 11:05:442067browse

Solution to garbled Chinese data uploaded by php: 1. Modify the character set in php encoding, the code is "header("Content-Type: text/html; charset=utf-8");"; 2. Check the character set of the library table and execute the "alter table ... convert to character set utf8;" statement.

What to do if php uploads Chinese data with garbled characters

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if the Chinese data uploaded to php is garbled?

What to do if php uploads Chinese data with garbled characters

First of all, the picture is wrong in the front, and it is corrected later

1. Modify the character set in the php encoding

header("Content-Type: text/html; charset=utf-8"); //一个地方
$link = @mysql_connect("localhost", "root", "root") or die("提示:数据库连接失败!");
mysql_query('SET NAMES UTF8');//两个地方,记住是utf8不是utf-8
mysql_select_db("test", $link);

2. Use editing software to see if the PHP file is encoded in UTF-8

3. If the above two steps have not been successful, you must consider the character set of the database table. Sure enough, my mistake was in the character set of the table. I executed the following statement

alter table 表的名称 convert to character set utf8;

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php uploads Chinese data with garbled characters. 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