PHP Function :
function generateCsv($data, $delimiter = ',', $enclosure = '"') {
$handle = fopen('php://temp', 'r+');
foreach ($data as $line) {
fputcsv($handle, $line, $delimiter, $enclosure);
}
rewind($handle);
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
return $contents;
}
사용 :
$data = array(
array(1, 2, 4),
array('test string', 'test, literal, comma', 'test literal "quotes"'),
);
echo generateCsv($data);
등록된 댓글이 없습니다.