Putting comma-separated data into a string
<?php
$sales = array( array('Northeast',12.54),
array('All Regions',1597.34) );
ob_start();
$fh = fopen('php://output','w') or die("Can't open php://output");
foreach ($sales as $sales_line) {
if (fputcsv($fh, $sales_line) === false) {
die("Can't write CSV line");
}
}
fclose($fh) or die("Can't close php://output");
$output = ob_get_contents();
ob_end_clean();
?>
Related examples in the same category