Skip to content

Instantly share code, notes, and snippets.

@ken-muturi
Created November 17, 2013 04:41
Show Gist options
  • Save ken-muturi/7509351 to your computer and use it in GitHub Desktop.
Save ken-muturi/7509351 to your computer and use it in GitHub Desktop.
Generate CSV from 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