国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

封裝導出csv文件類

2019-11-11 05:10:13
字體:
來源:轉載
供稿:網(wǎng)友

??摘要:使用場景,從數(shù)據(jù)表中取出utf-8的二維數(shù)組數(shù)據(jù),需要通過php輸出流的形式下載到客戶端,故封裝此類。

class ExportCsv { static function export($file_name = '',$table = array(),$header = array()){ $file_name = $file_name ? $file_name : 'default.csv'; if(!is_array($table) || (count($table) == 0)){ echo '無效數(shù)據(jù)'; exit(); } $now = gmdate("D, d M Y H:i:s"); header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); header("Cache-Control: max-age=0, no-cache, must-revalidate, application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); header("Content-Disposition: attachment;filename={$file_name}"); header("Content-Transfer-Encoding: binary"); ob_start(); $df = fopen("php://output", 'w'); if(is_array($header) && (count($header) != 0)){ $header = self::encodeSwitch($header); fputcsv($df, $header); } $table = self::encodeSwitch($table); foreach($table as $line){ fputcsv($df, $line); } fclose($df); ob_end_flush(); } static function encodeSwitch($a = array()){ $re = array(); if(!is_array($a)){ return false; } foreach($a as $k => $v){ if(is_array($v)){ $re[] = self::encodeSwitch($v); }else{ $re[] = mb_convert_encoding($v, 'gbk', 'utf-8'); } } return $re; }}

<完>


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 和龙市| 定南县| 奈曼旗| 靖江市| 镇赉县| 甘洛县| 瑞丽市| 石河子市| 东乡| 龙川县| 赤水市| 晋城| 北辰区| 克拉玛依市| 科技| 永和县| 陇南市| 文昌市| 桦甸市| 乐亭县| 喜德县| 赤城县| 喀什市| 慈溪市| 昭平县| 连平县| 名山县| 房产| 阜宁县| 崇信县| 尉犁县| 金秀| 金湖县| 杭锦后旗| 威信县| 石棉县| 福海县| 新闻| 瑞金市| 宕昌县| 尼木县|