首页 > 资源 > PHPquota 生成 CSV 文件

PHPquota 生成 CSV 文件

[导读]:?php$csv = "";foreach ($data as $row) { $csv .= join(",", $row) . "n";}echo $csv;? ?php function toCSV(array $data, array $colHeaders = array(), $asString = false) { $stream = ($asString) ? fopen("php://temp/maxmemory", "w+") : fo...
<?php
$csv = "";
foreach ($data as $row) {
    $csv .= join(",", $row) . "n";
}
echo $csv;
?>
 
<?php  
function toCSV(array $data, array $colHeaders = array(), $asString = false) {  
    $stream = ($asString)
        ? fopen("php://temp/maxmemory", "w+")
        : fopen("php://output", "w");  
 
    if (!empty($colHeaders)) {
        fputcsv($stream, $colHeaders);  
    }
 
    foreach ($data as $record) {
        fputcsv($stream, $record);
    }
 
    if ($asString) {
        rewind($stream);  
        $returnVal = stream_get_contents($stream);  
        fclose($stream);  
        return $returnVal;  
    }
    else {
        fclose($stream);  
    }  
}

本文来自投稿,不代表微盟圈立场,如若转载,请注明出处:https://www.vm7.com/a/ziyuan/111632.html