/** * 输出? 导出 csv格式 */ function export_csv($filename,$data) { ??? header("Content-type:textv"); ??? header("Content-Disposition:attachment;filename=".$filename); ??? header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); ??? header('Expires:0'); ??? header('Pragma:public'); ??? echo $data; }
?// csv导出方法 $str = "用户名,域名,开始时间,http,系统,数据\n"; $str = iconv('utf-8','gbk',$str);
foreach ($datas as $k=>$vo){ ??? $name????????? = iconv('utf-8','gbk',$vo['name']); ??? $domain_name??????????? = iconv('utf-8','gbk',$vo['domain_name']); ??? $start_date???????????? = iconv('utf-8','gbk',date('Y-m-d H:i:s', $vo['start_time'])) ??? $system???????????????? = iconv('utf-8','gbk',$system); ??? $data_value???????????? = $vo['data_value']; ??? $data_value???????????? = iconv('utf-8','gbk',$data_value);
??? $str .= $name.",". ??????????? $domain_name.",". ??????????? $start_date.",". ??????????? $http_type.",". ??????????? $system.",". ??????????? $data_value.",". ??????????? "\n"; }
$type_name = '请求数';
$filename = "test".$type_name."数据.csv"; export_csv($filename,$str);
exit;
|