封装导出csv文件类

  摘要:使用场景,从数据表中取出utf-8的二维数组数据,需要通过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 '无效数据';
            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, proxy-revalidate");
        header("Last-Modified: {$now} GMT");
        header("Content-Type: 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;
    }

}


<完>

SOT SOD TO DAP系列封装库AD库PCB库共155个(ALTIUM 3D封装库),3D封装列表如下: Component Count : 155 Component Name ----------------------------------------------- DPAK DPAK(to-252) DPAK2 /to263 DPAK2 78M05 PCBComponent_1 SOD-128 SOD-882 SOT-23 SOT-23 - 2 SOT-23-1 SOT-23-3-431 SOT-23-431 SOT-23A SOT-23M SOT-23N SOT-23P SOT-25 SOT-89 SOT-89-2 SOT-89-3 SOT-89-5 SOT-89-431 SOT-89-NPN SOT-223 SOT-223 - 3 SOT23 SOT23-5 SOT23-6 SOT323 SOT523 SOT669 TO-3 TO-5 TO-18 TO-39 TO-46 TO-52 TO-66 TO-72 TO-92 TO-92-431 TO-92-431-2 TO-92-667 TO-92-3904 TO-92-MCR100 TO-92-N TO-92-NPN TO-92-P TO-92A TO-92A-2 TO-92B TO-92B-2 TO-92C TO-92C-2 TO-126 TO-126-H TO-126-H2 TO-126V TO-202H TO-202V TO-202VS TO-218H TO-218V TO-218V-2 TO-220 TO-220_3 TO-220_5 TO-220_5PKG TO-220 - 2 TO-220-1 TO-220-1-DIODE TO-220-2 TO-220-3 TO-220-3-hink TO-220-3S TO-220-5 TO-220-5S TO-220-5V TO-220-7S TO-220-7815 TO-220-LM TO-220-LM-3 TO-220-YA TO-220-YB TO-220-YHR TO-220-YHR-DIODE TO-220-YV35V TO-220AB TO-220AB-1 TO-220AB2 TO-220AC TO-220H TO-220H-2 TO-220H-3 TO-220H-4 TO-220HS TO-220LS TO-220LS-DIODE TO-220LSA TO-220LSB TO-220SM TO-220SM-1 TO-220SS TO-220V TO-220V-1 TO-220V-3 TO-220V-3.8mm TO-220V-AC TO-220VS TO-220VS-1 TO-220YK-2H TO-220YK-2V TO-220YK-3V TO-220YW-2V TO-220YW-3V TO-237 TO-247 TO-247 - 2 TO-247 - duplicate TO-247-YA TO-247-YB TO-247AD TO-247BB TO-247D TO-247H TO-247H - IGBT TO-247H-1 TO-247H-2 TO-247H-4 TO-247H-DIODE TO-247LS TO-247V TO-247V-2 TO-247V-3 TO-251 TO-251H TO-251V TO-252 TO-257H TO-257V TO-262-SM TO-262-V TO-263 TO-263-3 TO-263-5 TO-263-5-2 TO-263-IRF264 TO-263S TO-264-AA TO-264-H TO-264-V TO-264H TO-264V TO-7805 TO-IR424G
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值