整理文档,搜刮出一个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;
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持网页设计。