Home >Backend Development >PHP Problem >What to do if the file name created by php is garbled

What to do if the file name created by php is garbled

藏色散人
藏色散人Original
2021-09-20 13:46:202292browse

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.

What to do if the file name created by php is garbled

#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!

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