Blogger Information
Blog 21
fans 0
comment 0
visits 21110
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php导出csv文件
星辰大海
Original
1108 people have browsed it

实例

<?php
$ret = [
  ['a'=>'a1','b'=>'b1','c'=>'c1'],
  ['a'=>'a2','b'=>'b2','c'=>'c2'],
  ['a'=>'a3','b'=>'b3','c'=>'c3']
];
$fileName = 'abc.csv';
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=" . $fileName);
header("Cache-Control: max-age=0");

$file = fopen("php://output", 'a');
$head = ["列A", "列B", "列C"];
fputcsv($file, $head);
foreach ($ret as $row) {
    fputcsv($file, $row);
}
fclose($file);
die;

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post