求數(shù)據(jù)保存到csv文件的方法。
1 回答

牽豬的倉鼠
TA貢獻(xiàn)3條經(jīng)驗(yàn) 獲得超0個(gè)贊
輸出csv 跟框架無關(guān),我給你一個(gè)代碼
//?數(shù)據(jù)導(dǎo)出組件 final?class?SimpleDataExport?{ static?function?generateResponseHeader($filename,$charset='UTF-8',$mimeType?=?'application/octet-stream'){ header("Pragma:?public");???header("Expires:?0"); header("Cache-Control:?must-revalidate,?post-check=0,?pre-check=0"); header("Content-Type:?application/force-download"); header("Content-Type:?{$mimeType};?charset={$charset}"); header("Content-Transfer-Encoding:?binary"); header(self::cDispositionHeader($_SERVER["HTTP_USER_AGENT"],$filename,'attachment',$charset)); } static?function?cDispositionHeader($httpUserAgent,$filename,$contentDisposition='attachment',$charset?=?'UTF-8'){ //?文件名亂碼問題 if?(preg_match("/MSIE/",?$httpUserAgent))?{ $filename?=?urlencode($filename); $filename?=?str_replace("+",?"%20",?$filename);//?替換空格 $attachmentHeader?=?"Content-Disposition:?{$contentDisposition};?filename=\"{$filename}\";?charset={$charset}"; }?else?if?(preg_match("/Firefox/",?$httpUserAgent))?{ $attachmentHeader?=?'Content-Disposition:?'.$contentDisposition.';?filename*="utf8\'\''?.?$filename.?'"'?; }?else?{ $attachmentHeader?=?"Content-Disposition:?'.$contentDisposition.';?filename=\"{$filename}\";?charset={$charset}"; } return?$attachmentHeader; } } /** ?*?簡易?csv?數(shù)據(jù)導(dǎo)出類 ?*? ?*/ class?SimpleCsvExport?{ static?function?generateXlsHeader($filename){ SimpleDataExport::generateResponseHeader($filename,'utf-8','text/csv'); echo(chr(0xEF).chr(0xBB).chr(0xBF)); } static?function?writeRow(array?$row){ echo?implode(',',$row)?.?PHP_EOL; } }
- 1 回答
- 0 關(guān)注
- 1760 瀏覽
添加回答
舉報(bào)
0/150
提交
取消