1、设置header头
header("Content-type: application/vnd.ms-excel; charset=UTF-8"); // 文件编码
header("Content-type: application/octet-stream");//流文件
header("Content-Disposition:attachment;filename = xxx.csv" );
2、输出
$fp = fopen(‘php://output‘, ‘w‘);
fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF)); // 设置编码的文件头
fputcsv($fp, $arr);