Skip to content

Instantly share code, notes, and snippets.

@ajbonner
Last active December 26, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajbonner/7142414 to your computer and use it in GitHub Desktop.
Save ajbonner/7142414 to your computer and use it in GitHub Desktop.
A version of putcsv that returns a string rather than writes to a file
<?php
/**
* @param array $data
* @return string
*/
public function str_putcsv($data)
{
$fh = fopen('php://memory', 'rwb');
fputcsv($fh, $data);
fseek($fh, 0);
$csv = fgets($fh);
fclose($fh);
return $csv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment