Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write CSV To File Without Enclosures In PHP

Is there a native function or solid class/library for writing an array as a line in a CSV file without enclosures? fputcsv will default to " if nothing is passed in for the enclosure param. Google is failing me (returning results for a whole bunch of pages about fputcsv), and PEAR's libraries do more or less the same things as fputcsv.

Something that works exactly like fputcsv, but will allow the fields to remain unquoted.

currently: "field 1","field 2",field3hasNoSpaces

desired: field 1,field 2,field3hasNoSpaces

like image 770
Derek Reynolds Avatar asked Nov 25 '09 23:11

Derek Reynolds


1 Answers

The warnings about foregoing enclosures are valid, but you've said they don't apply to your use-case.

I'm wondering why you can't just use something like this?

<?php $fields = array(     "field 1","field 2","field3hasNoSpaces" ); fputs(STDOUT, implode(',', $fields)."\n"); 
like image 161
oops Avatar answered Oct 05 '22 23:10

oops