Solution to garbled file names created by php: 1. Create a PHP sample file; 2. Pass "rename('a.zip',iconv('UTF-8', 'GB2312//IGNORE', 'Chinese a.zip'));" method can be modified into a Chinese file name.
#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.
What should I do if the created file name is garbled?
The Chinese file name generated by php will become garbled. It should be solved like this
Now PHP has many class libraries that will generate files, such as generating zip files, generating QR codes, etc. wait. These libraries are very fun to use, but once a file name with Chinese characters is generated, it is very likely that garbled characters will appear.
Problem:
The generated Chinese file name will become garbled characters
Solution:
Use function: iconv(), rename()
When generating a file name, directly generate an English name, such as: a.zip, c.zip, etc. Then, use PHP's function rename to move files.
rename('a.zip',iconv('UTF-8', 'GB2312//IGNORE', '中文a.zip'));
Ignore means to ignore errors during conversion. Without the ignore parameter, all strings following this character cannot be saved.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if the file name created by php is garbled. For more information, please follow other related articles on the PHP Chinese website!