Skip to content

Instantly share code, notes, and snippets.

@jwheare
Created June 23, 2009 17:45
Show Gist options
  • Save jwheare/134706 to your computer and use it in GitHub Desktop.
Save jwheare/134706 to your computer and use it in GitHub Desktop.
php array to csv line
<?php
// Encode an array to a CSV delimited row using PHP's memory output buffer
// http://php.net/manual/en/wrappers.php.php
function array_to_csv_line($data_array) {
$temp_mem = fopen("php://temp", 'r+');
fputcsv($temp_mem, $data_array);
rewind($temp_mem);
$data_csv = trim(stream_get_contents($temp_mem));
return $data_csv;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment