整理文檔,搜刮出一個php實現(xiàn)CSV格式文件輸出,稍微整理精簡一下做下分享。本文主要和大家介紹了幾行php代碼實現(xiàn)CSV格式文件輸出,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望能幫助到大家。
//適用于不需要設置格式簡單將數(shù)據(jù)導出的程序,多多指教...... $str .= 'pro_code'.','.'words'.'\n';//首先寫入表格標題欄 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); //導出 //自定義輸出函數(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; }
相關推薦:
log4Net 高性能寫入和CSV格式的實例詳解
完美解決php 導出excle的.csv格式的數(shù)據(jù)時亂碼問題
HTML表格的每行轉為CSV格式數(shù)組
以上就是幾行php代碼實現(xiàn)CSV格式文件輸出案例的詳細內容,更多請關注php中文網(wǎng)其它相關文章!