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
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");
works with chr() function:
fputcsv($f,$array,',',chr(0));
fputcsv($file, $data, ';', chr(127));