Home > Backend Development > PHP Tutorial > How to solve the problem of Chinese garbled characters in cross-browser PHP download file names, _PHP tutorial

How to solve the problem of Chinese garbled characters in cross-browser PHP download file names, _PHP tutorial

WBOY
Release: 2016-07-13 10:05:16
Original
884 people have browsed it

How to solve the problem of Chinese garbled characters in cross-browser PHP download file names,

This article describes the solution to the problem of Chinese garbled characters in cross-browser PHP download file names. Share it with everyone for your reference. The details are as follows:

Copy code The code is as follows: $ua = $_SERVER["HTTP_USER_AGENT"];
$filename = "Chinese file name.txt";
$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_filename);
header('Content-Type: application/octet-stream');
if (preg_match("/MSIE/", $ua)) {
header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment; filename*="utf8''' . $filename . '"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '"');
}
print 'ABC';
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963849.htmlTechArticleHow to solve the problem of Chinese garbled characters in cross-browser PHP download file names. This article describes the cross-browser PHP download with examples. Solution to the problem of Chinese garbled characters in file names. Share it with everyone for everyone...
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