当前位置:Gxlcms > PHP教程 > 从PHP数据创建CSV文件

从PHP数据创建CSV文件

时间:2021-07-01 10:21:17 帮助过:37人阅读

  1. function generateCsv($data, $delimiter = ',', $enclosure = '"') {
  2. $handle = fopen('php://temp', 'r+');
  3. foreach ($data as $line) {
  4. fputcsv($handle, $line, $delimiter, $enclosure);
  5. }
  6. rewind($handle);
  7. while (!feof($handle)) {
  8. $contents .= fread($handle, 8192);
  9. }
  10. fclose($handle);
  11. return $contents;
  12. }

用法:
  1. $data[0] = "apple";
  2. $data[1] = "oranges";
  3. generateCsv($data, $delimiter = ',', $enclosure = '"');
  4. ?>

PHP, CSV

人气教程排行