《PHP實戰:詳解php幾行代碼實現CSV格式文件輸出》要點:
本文介紹了PHP實戰:詳解php幾行代碼實現CSV格式文件輸出,希望對您有用。如果有疑問,可以聯系我們。
整理文檔,搜刮出一個php實現CSV格式文件輸出,稍微整理精簡一下做下分享.
PHP實戰
//適用于不需要設置格式簡單將數據導出的程序,多多指教...... $str .= 'pro_code'.','.'words'.'\n';//首先寫入表格標題欄 foreach($is_error as $key => $value){//循環寫入數據 $str .= $value['pro_code'].",".$value['words']."\n"; } $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; }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持維易PHP.PHP實戰
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/551.html