我已经创建了生成CSV文件的功能。但是,它不能在Windows excel上正确显示特殊字符。我在下面做了小代码示例
$BOM = "\xEF\xBB\xBF"; // UTF-8 BOM
$file = tempnam(sys_get_temp_dir(), 'mycsv');
$fh = fopen($file, 'w');
fwrite($fh, $BOM); // NEW LINE
$symbol = '€';
fputcsv($fh, [$symbol]);
fputcsv($fh, [199]);
fclose($fh);
return response()->download($file, 'account.csv', [
'Content-Type' => 'text/csv; charset=UTF-8',
'Content-Encoding' => 'UTF-8',
'Content-Disposition' => "attachment; filename='account.csv'",
]);
有人可以在这里指出问题吗?