Created
January 29, 2018 14:16
-
-
Save Bizunow/411662b8876e05587d6c138ef4a13b71 to your computer and use it in GitHub Desktop.
[String to CSV] #php
This file contains hidden or 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
function str_putcsv($data) | |
{ | |
$fh = fopen('php://temp', 'rw'); | |
// write out the headers | |
fputcsv($fh, array_keys(current($data))); | |
// write out the data | |
foreach ( $data as $row ) { | |
fputcsv($fh, $row); | |
} | |
rewind($fh); | |
$csv = stream_get_contents($fh); | |
fclose($fh); | |
return $csv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment