一起源码网

标题: 几行php代码实现CSV格式文件输出案例 [打印本页]

作者: 云文章    时间: 2020-6-2 15:30
标题: 几行php代码实现CSV格式文件输出案例
整理文档,搜刮出一个php实现CSV格式文件输出,稍微整理精简一下做下分享。本文主要和大家介绍了几行php代码实现CSV格式文件输出,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧,希望能帮助到大家。


//适用于不需要设置格式简单将数据导出的程序,多多指教......

$str .= 'pro_code'.','.'words'.'
';//首先写入表格标题栏

foreach($is_error as $key => $value){//循环写入数据

  $str .= $value['pro_code'].",".$value['words']."
";

}

$str = iconv('utf-8','gb2312',$str);//防止中文乱码

$filename = "./output.csv";//文件路径及名字

export_csv($filename,$str); //导出

 

//自定义输出函数
function export_csv($filename,$str){

  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 $str;

}



作者: 极度抢购客服    时间: 2022-7-26 23:54
怎么查看图片的代码




欢迎光临 一起源码网 (https://www.171739.xyz/) Powered by Discuz! X3.3