Does anyone know of a function, or a cool trick, to get the return value of fputcsv
instead of writing the output to file?
I'm trying to encode a file as a tab-delimited file, but my client wants one of the columns encoded in csv (so 1 column of csv values in a tab delimited file). Not ideal, I agree, but at this point I just need to get it done.
Thanks!
Shamelessly copying from a user note on the documentation page:
$buffer = fopen('php://temp', 'r+');
fputcsv($buffer, $data);
rewind($buffer);
$csv = fgets($buffer);
fclose($buffer);
// Perform any data massaging you want here
echo $csv;
All of this should look familiar, except maybe php://temp
.
$output = fopen('php://output', 'w');
fputcsv($output, $line);
fclose($output);
Or try one of the other supported wrappers, like php://memory
if you don't want to output directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With