Forked from weivall/Generate CSV file from a PHP array
Created
November 11, 2013 22:44
-
-
Save mikedugan/7421906 to your computer and use it in GitHub Desktop.
generates a csv file from a php array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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