gongzhonghao.png
扫码关注我们
最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

php实现CSV格式文件输出实例详解

来源:http://erdangjiade.com/topic/2413.html 你好,世界。 2017-09-25 22:42浏览(90)

本篇文章主要介绍了详解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;

}

以上就是php实现CSV格式文件输出实例详解的详细内容,更多请关注二当家的素材网其它相关文章!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2