PHP 生成 CSV 文件
知識
07-06
<?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);
}
}
※Hello Jmr程序
※spring aop的基於xml的配置
TAG:程序員小新人學習 |