Home > Backend Development > PHP Problem > 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

藏色散人
Release: 2023-03-04 12:08:01
Original
2173 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template