I want to rewrite the code below to generate a string. This string I want to attach to an eamil. It should appear as a csv file.
$fh = fopen($file,'w');
function __outputCSV(&$vals, $key, $filehandler) {
fputcsv($filehandler, $vals, ';', '"');
}
array_walk($aData, '__outputCSV', $fh);
fclose($fh);
Any idea’s?
The obvious and lazy approach would be not to rewrite it, but to simply create a temp file and call
file_get_contents()on it afterwards.This, however, would be boring, so I’m going to suggest what is arguably an over complicated approach, but it should work nicely and will be done entirely in memory:
Use this class that is provided in the PHP manual as an example of how to write a custom protocol handler, and the following example code: