Question

I'm creating a CSV file using the SPLFile class:

$z=new SplFileObject('/tmp/test.csv.gz','w');
$arr=[['a','b','c'],[1,2,3],[2,4,8],[3,6,9]];
foreach($arr as $f) $z->fputcsv($f);

Is there a way to gz-compress my output?

Thanks

gm

Was it helpful?

Solution

You can use wrappers. In this case you can use zlib.

$z=new SplFileObject('compress.zlib:///tmp/test.csv.gz','w');
$arr=[['a','b','c'],[1,2,3],[2,4,8],[3,6,9]];
foreach($arr as $f) $z->fputcsv($f);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top