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+');
fprintf
($fp, chr(0xEF).chr(0xBB).chr(0xBF));
fputcsv
($fp, ......

(I got to know this idea from blog.foolbird.net/1517.html)

 

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