$data = array(
array(
'create_time' => '2021-09-01',
'ids' => '001',
'title' => '编号一',
'name' => '张三'
),
array(
'create_time' => '2021-09-02',
'ids' => '002',
'title' => '编号二',
'name' => '李四'
),
array(
'create_time' => '2021-09-03',
'ids' => '003',
'title' => '编号3',
'name' => '王五'
)
);
exportCsv($data);
function exportCsv($data){
$filename = '列表_'.date('YmdHis', time()).'.csv';
$fileData = '序号, 编号, 标题, 姓名, 时间' . "\n";
foreach($data as $key=>$val){
$temp = $key+1 . ',' .
$val['ids'] . "\t" . ',' .
$val['title'] . "\t" . ',' .
$val['name'] . "\t" . ',' .
$val['create_time'] . "\t";
$fileData .= $temp. "\n";
}
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=" . $filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $fileData;
exit;
}
|