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