Skip to content

Instantly share code, notes, and snippets.

@elliotboney
Created July 3, 2014 02:03
Show Gist options
  • Save elliotboney/2f9132a1e346824fe68c to your computer and use it in GitHub Desktop.
Save elliotboney/2f9132a1e346824fe68c to your computer and use it in GitHub Desktop.
Create csv file from php array
<?php
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