兵兵有你

人品好,气质差.丢了工作就回家...

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
$headArr=['姓名','身高','','位置'];//列名
$data = [['aa',12,'b'],['bb',13,'c'],['dd',34,'e]]; //数据

function exportToExcel($fileName = '', $headArr = [], $data = []){
    ini_set('memory_limit','1024M');
    ini_set('max_execution_time',0);
    ob_end_clean();
    ob_start();
    header("Content-Type: text/csv");
    header("Content-Disposition:filename=".$fileName.'.csv');
    $fp=fopen('php://output','w');
    fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));
    fputcsv($fp,$headArr);
    $index = 0;
    foreach ($data as $item) {
        if($index==1000){
            $index=0;
            ob_flush();
            flush();
        }
        $index++;
        fputcsv($fp,$item);
    }
    ob_flush();
    flush();
    ob_end_clean();
    exit();
}

  2.生成随机字符串

function bing_rand($length = 32, $char = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
    if(!is_int($length) || $length < 0) {
        return false;
    }
    $string = '';
    for($i = $length; $i > 0; $i--) {
        $string .= $char[mt_rand(0, strlen($char) - 1)];
    }
    return $string;
}

 

posted on 2021-01-18 17:33  greatbing  阅读(408)  评论(0编辑  收藏  举报