Home >Backend Development >PHP Tutorial >Solve the problem of Chinese garbled characters imported into mysql from php csv files
When using php to import csv files into mysql database, Chinese garbled characters appeared. Here I will share the solution for the reference of friends in need.
Many methods are to read and upload the contents of the csv file into the mysql database. At this time, the Chinese display may be garbled. Even after the data is transcoded with the iconv function, it is still garbled. You can consider using the setlocale() function to handle it. This function is used to configure regional information. Use this function to define it before reading and writing csv data. For example, if the csv file is in UTF-8 format without BOM, you can use the following function to define it first: setlocale(LC_ALL, ‘zh_CN.UTF8′); Then, use the iconv function to transcode the data content and store it in the database, and then perform some subsequent operations. |