The example in this article describes how to solve 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:
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.
http://www.bkjia.com/PHPjc/963985.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963985.htmlTechArticleSolution to the problem of Chinese garbled characters in cross-browser PHP download file names This article mainly introduces cross-browser PHP The solution to the Chinese garbled problem in the download file name involves PHP for Chinese...