国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 林州市| 大渡口区| 贺州市| 蓬安县| 巴林右旗| 兴隆县| 扬州市| 开原市| 梁平县| 新蔡县| 绍兴市| 儋州市| 大荔县| 永平县| 永寿县| 海伦市| 泽普县| 邵东县| 明溪县| 武邑县| 德江县| 卫辉市| 丹寨县| 永宁县| 连城县| 武功县| 南投县| 林口县| 新田县| 汕头市| 华蓥市| 方城县| 曲阜市| 温泉县| 眉山市| 大洼县| 吉林省| 高平市| 安吉县| 巨鹿县| 上高县|