Home > Article > Backend Development > What to do if php uploads Chinese data with garbled characters
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.
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?
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!