php 导出csv
1.下面是一個非常簡單的例子,你可以復制下來運行就可以了,代碼如下:
header('Content-Type: application/vnd.ms-excel;charset=gbk');
header('Content-Disposition: attachment;filename=test_' . time() . '.csv');
header('Cache-Control: max-age=0');
$list = array
(
"George,John,Thomas,USA",
"James,Adrew,Martin,USA",
);
$file = fopen('php://output', 'a');
foreach ($list as $line)
{
fputcsv($file,explode(',',$line));
}
fclose($file);
header('Content-Type: application/vnd.ms-excel;charset=gbk');
header('Content-Disposition: attachment;filename=test_' . time() . '.csv');
header('Cache-Control: max-age=0');
$list = array
(
"George,John,Thomas,USA",
"James,Adrew,Martin,USA",
);
$file = fopen('php://output', 'a');
foreach ($list as $line)
{
fputcsv($file,explode(',',$line));
}
fclose($file);
轉載于:https://www.cnblogs.com/kobigood/p/6937408.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
- 上一篇: 测试实例
- 下一篇: Gym - 101334F 单调栈