Home  >  Article  >  Backend Development  >  How to solve the problem of Chinese garbled file names in PHP IE

How to solve the problem of Chinese garbled file names in PHP IE

藏色散人
藏色散人Original
2020-08-13 10:21:502121browse

php IE Chinese garbled solution: first determine whether all browsers downloading files are IE browsers; then perform urlencode escape encoding on the file name to solve the garbled problem.

How to solve the problem of Chinese garbled file names in PHP IE

Recommended: "PHP Video Tutorial"

Solution to php file download IE file name Chinese garbled

During programming, when PHP downloads a file, the file name appears with Chinese garbled characters, but browsers such as Firefox and Google are fine.

Methods/Steps

The solution is very simple. Determine whether all browsers for downloading files are IE browsers. If so, just perform urlencode() escape encoding on the file names.

How to solve the problem of Chinese garbled file names in PHP IE

As shown in the picture above

$userBrowser = $_SERVER['HTTP_USER_AGENT'];$fileName = "fileName文件名.csv";if ( preg_match( '/MSIE/i', $userBrowser ) ) {    $fileName = urlencode($fileName);}$fileName = iconv('UTF-8', 'GBK//IGNORE', $fileName);

Notes

Since this problem only exists in IE, it is best to determine whether it is under IE before performing urlencode() escape encoding

The above is the detailed content of How to solve the problem of Chinese garbled file names in PHP IE. 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