Home >Backend Development >PHP Problem >How to solve the problem of Chinese garbled file names in PHP IE
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.
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.
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!