We now download an order txt file from the Japanese website every day and import it to the database through PHP, now, we need to convert the txt file into UTF-8 in notepad every time before importing the file. direct import is garbled. how can we use PHP to transcode the file without using notepad every time ???
The following are some information for analysis.
Server characterset latin1
Db characterset latin1
Client chatacterset latin1
Conn. chatacterset latin1
Character_set_client latin1
Character_set_connection latin1
Character_set_database latin1
Character_set_filesystem latin1
Character_set_results latin1
Character_set_server latin1
Character_set_system latin1
Character_sets_dir latin1
Some codes are as follows:
mysql_query("set names utf-8");$ship_address3=mb_convert_encoding(addslashes($u[19]), 'UTF-8','auto');
Reply to discussion (solution)
Whether to transcode or transcode depends on the raw data.
If you say "convert txt to UTF-8 using Notepad", can you correctly display the content when you open this file using Notepad? No garbled characters?
Are you using a Japanese operating system?
If possible, you can paste data file fragments for analysis.
Echo base64_encode(file_get_contents('your data file .txt ', false, null, 0, 40 ));
Post result
You can see it when you open it.
If you really want my help, please follow what I said.
It makes no sense to paste an image.
Output result:
B3jkzxitawqjb3jkzxitaxrlbs1pzarwdxjjarfzzs1kyxrlcxbheq =
Systems, such as Japanese, traditional Chinese, and simplified Chinese are all possible, but they are mainly Japanese systems.
What is the common use of base64_encode () in xuzuning?
Confirm again, what is your operating system? Please be sure to answer
Based on your descriptions, images, and data fragments
1. convert the txt file to UTF-8 in notepad every time. Obviously, the text is not UTF-8, otherwise conversion is not required.
2. the operating system is of the window series, otherwise there will be no "notepad"
3. there is no BOM header in the data, that is, it is saved using the default character set of the operating system.
4. from the picture, the Japanese part seems to be complete and garbled characters are not observed.
We can see that
If the operating system is in simplified Chinese, the character set is gbk
If the operating system is traditional Chinese, the character set is big5
If the operating system is Japanese, the character set is EUC or shift-JIS.
Therefore, you only need to enter the following statement in the character set of the operating system for operating the data file.
Mysql_query ("set names character set ");
Transcoding is automatically completed by mysql.
Xuzuning: Hello!
A: We downloaded the data from amazon Japan. the operator's system is generally in traditional Chinese and Japanese. if you cannot implement multiple systems, take the Japanese system as the standard. we can ask the operator to use all Japanese systems.
1. notepad displays ansi encoding
2. many Japanese websites I visit are encoded with shift-jis.
I would like to ask, if I use EUC or shift-JIS, will it be a problem if we use simplified or traditional display ??
Most Japanese websites are accessed using shift-jis encoding.
The downloaded file is shift-jis encoded, and the imported database uses shift-jis encoding.
Simplified or traditional Chinese is a Chinese concept and has nothing to do with Japanese
When you operate on simplified or traditional data sources, is it gbk or big5?
Isn't UTF-8 stored in the database eventually?
Isn't it the same?
Well, thanks, xuzuning! I'll try it today!
Our practice is to convert the download order to an excel format and then read it through php.
Zy205817 Hello, this is the same as converting UTF-8 with notepad. you have to manually convert the code once.
Xuzuning is huge. can PHP transcode txt files? Just like we use notepad for transcoding ???
Xuzuning:
The last time I had no garbled characters in Japanese, this is the txt document that my colleague gave me. today I downloaded it from the Japanese website. The Japanese part is garbled and I need to use excel for transcoding, I can't use notepad to convert uft-8 directly