ddeboer / data-import

Import data from and export data to a range of different file formats and media
MIT License
567 stars 123 forks source link

Force the enclosure character with the CSV writer #320

Closed danakil closed 7 years ago

danakil commented 7 years ago

The CSV writer use the standard php fputcsv(), which will only wraps the value under the following circumstances:

May it be possible to add an option (or create a new writer, or some other method) to force the enclosure character (in other word, to no use fputcsv but some custom code) when required ?

ddeboer commented 7 years ago

this can lead to problem with systems that explicitly require that all fields are wrapped in quotes

But those systems don’t adhere to the RFC for CSV, which states that only

[f]ields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes.

So while we won’t add this to the core, you can still enclose your values in (say) double quotes by adding a converter.