First figure out, what is the BOM header? When you save a text file in UTF-8 format with a program such as Notepad under Windows, Notepad adds several invisible characters (the EF BB BF) to the file header, which is the so-called BOM (Byte order Mark).
Not limited to Notepad saved files, as long as the opening of the file contains several invisible characters of the EF BB BF (16 binary should be XEFXBBXBF, with binary edit file visible). This is like a conventional thing, when the system sees this thing, it will feel you this file is UTF-8 encoded.
If your interface is UTF-8, you need to force download a file, such as Csv.excel in the default (Chinese background), that the CSV is GB encoding, so if the meter has a BOM header, then you give the user to present files, may be garbled.
How to add BOM head?
Add the BOM header to the output file before you can:
Copy the Code code as follows:
Filename
$filename = "Www.jb51.net.net.csv";
Header (' Expires: '. Gmdate (' d, D M Y h:i:s ', $_server[' request_time '] + 10). ' GMT ');
Header (' cache-control:max-age=10 ');
Header (' Content-type:application/vnd.ms-excel; Charset=utf-8 ');
Header (' content-type:text/csv; Charset=utf-8 ');
Header ("content-disposition:attachment; filename={$filename} ");
If there is a hint in the result, change the first line output to the message text
$out = "XEFXBBXBF";//Plus BOM header, System automatically defaults to UTF-8 encoding
if (!empty ($extra [' notice '])) {
$out. = "{$extra [' notice ']}rn";
}
Output
foreach ($table as $row) {
$out. = Implode (",", $row). "RN";
}
/* if (mb_detect_encoding () ($out) = = ' UTF-8 ') {
$out = Iconv ("Utf-8//ignore", "GBK", $out);
} */
Echo $out;
http://www.bkjia.com/PHPjc/684745.html www.bkjia.com true http://www.bkjia.com/PHPjc/684745.html techarticle first figure out, what is the BOM header? When you save a text file in UTF-8 format under Windows with a program such as Notepad, Notepad adds several invisible characters (... ) to the file header.