欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解php幾行代碼實(shí)現(xiàn)CSV格式文件輸出

 更新時(shí)間:2017年07月01日 08:45:04   作者:余文波  
本篇文章主要介紹了詳解php幾行代碼實(shí)現(xiàn)CSV格式文件輸出,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

整理文檔,搜刮出一個(gè)php實(shí)現(xiàn)CSV格式文件輸出,稍微整理精簡一下做下分享。

//適用于不需要設(shè)置格式簡單將數(shù)據(jù)導(dǎo)出的程序,多多指教......

$str .= 'pro_code'.','.'words'.'\n';//首先寫入表格標(biāo)題欄

foreach($is_error as $key => $value){//循環(huán)寫入數(shù)據(jù)

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

}

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

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

export_csv($filename,$str); //導(dǎo)出

 

//自定義輸出函數(shù)
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;

}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論