excel大批量导出数据&生成随机字符串

$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;
}
原文地址:https://www.cnblogs.com/bing2017/p/14293839.html