解決導出CSV文件用office excel打開亂碼的問題

http://www.phpfensi.com/php/20131207/816.html

關鍵是print 那段代碼。

function ExportCsv($titles,$filename,$data){
print(chr(0xEF).chr(0xBB).chr(0xBF));//设置utf-8 + bom ,处理汉字显示的乱码
header ( 'Content-Type: application/vnd.ms-excel;charset=utf-8' );
header ("Content-Transfer-Encoding: binary");
header ( 'Content-Disposition: attachment;filename="' . $filename . '.csv"' ); //"'.$filename.'.xls"
header ( 'Cache-Control: max-age=0' );
$output = fopen('php://output', 'w');

fputcsv($output, $titles);
foreach ($data as $key => $value) {
fputcsv($output, $value);
}
fclose($output);
}

你可能感兴趣的:(php)