从PHP数据创建CSV文件
时间:2021-07-01 10:21:17
帮助过:37人阅读
- 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[0] = "apple";
- $data[1] = "oranges";
- generateCsv($data, $delimiter = ',', $enclosure = '"');
- ?>
|
PHP, CSV