开发者

Get return value of fputcsv

开发者 https://www.devze.com 2023-04-04 06:40 出处:网络
Does anyone know of a function, or a cool trick, to get the return value of fputcsv instead of writing the output to file?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消