First of all, what is the BOM header? When you save a text file in UTF-8 format with a program like Notepad under Windows, Notepad adds a few invisible characters (the EF BB BF) to the front of the file, which is the so-called BOM (Byte order Mark).
Not limited to Notepad saved files, as long as the openings in the file contain the EF BB BF several invisible characters (16 should be xefxbbxbf, visible with binary editing files). This is like a conventional thing, when the system sees this thing, it will feel that you this file is UTF-8 code.
If your interface is UTF-8, you need to force download a file, such as Csv.excel in the default (Chinese background), that CSV is GB code, so if the meter has a BOM head, then you give the user presented files, may be garbled.
How to add BOM head?
You can add a BOM header before you output the file:
code is as follows |
&nbs P; |
& nbsp; //filename $filename = "File.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} ");  &NBSP //If there is a hint in the result, change the first row output to the prompt message text $out = "XEFXBBXBF";//Plus BOM header, The system automatically defaults to the UTF-8 encoding if ($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; |