很简单,看内容,不多说了:
<?php
//设置标题
$header[] = "ID";
$header[] = "订单";
$header[] = "模式";
$header[] = "账号";
$header[] = "角色ID";
$header[] = "角色名";
$header[] = "元宝";
$header[] = "金额";
$header[] = ‘IP‘;
$header[] = "时间";
$info[] = $header;
//设置内容
$tmp[1] = 1;
$tmp[2] = 2;
$tmp[3] = 3;
$tmp[4] = 4;
$tmp[5] = 5;
$tmp[6] = 6;
$tmp[7] = 7;
$tmp[8] = 8;
$tmp[9] = 9;
$tmp[10] = ‘2015‘;
$info[] = $tmp;
//文件名
$file = date("Ymd_His",mktime()).‘.csv‘;
ini_set(‘memory_limit‘, ‘1024M‘);//内存最大占用
//header(‘Content-Type: text/csv‘);//内容类型
header(‘Content-Type: text/vnd.ms-excel‘);//内容类型
header(‘Content-Disposition: attachment;filename=‘.$file);
$fp = fopen(‘php://output‘, ‘w‘);//打开文件
foreach($info AS $row){
$fields = array();
foreach($row AS $val){
$fields[] = iconv(‘utf-8‘, ‘gbk‘, $val);//设置编码
}
fputcsv($fp, $fields);//写入
}
fclose($fp);//关闭
?>