Skip to content

Instantly share code, notes, and snippets.

@mikedugan
Forked from weivall/Generate CSV file from a PHP array
Created November 11, 2013 22:44
Show Gist options
  • Save mikedugan/7421906 to your computer and use it in GitHub Desktop.
Save mikedugan/7421906 to your computer and use it in GitHub Desktop.
generates a csv file from a php array
//generates a csv file given an array
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment