php几行代码实现CSV格式文件输出

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

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

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

  $str .= $value['pro_code'].",".$value['words']."\n";utf-8

}it

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

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

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

 

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

  header("Content-type:text/csv");foreach

  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;

}

相关文章
相关标签/搜索