As we know, there is a function in PHP called fputcsv that can transfer array into CSV line.

However, if you make a CSV file only with these CSV lines, containing UTF8 characters, the generated CSV file will became a chaos in Excel.


Solution example:

$fp = fopen("php://temp", 'r+');
($fp, chr(0xEF).chr(0xBB).chr(0xBF));
($fp, ......

(I got to know this idea from


Reason: the 0xEF 0xBB 0xBF BOM header will let Excel know the correct encoding.