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

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

封裝導(dǎo)出csv文件類

2019-11-11 03:34:29
字體:
供稿:網(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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 武功县| 海宁市| 牙克石市| 广汉市| 永胜县| 慈利县| 扎囊县| 萝北县| 咸宁市| 肇东市| 平阳县| 建平县| 乡宁县| 镇赉县| 遵义县| 桐梓县| 富川| 万年县| 梅河口市| 温泉县| 禹州市| 大竹县| 平度市| 洪泽县| 保山市| 雅安市| 益阳市| 固始县| 无为县| 铁岭市| 安宁市| 交口县| 息烽县| 五大连池市| 元朗区| 平武县| 云和县| 中宁县| 五大连池市| 红安县| 南陵县|