Home  >  Article  >  Backend Development  >  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
WBOYOriginal
2016-07-13 10:04:52705browse

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

This article mainly introduces the solution to the problem of Chinese garbled characters in cross-browser PHP download file names. It involves PHP transcoding techniques for Chinese encoding, which has certain reference value. Friends in need can refer to it

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.

www.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...
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