Extension Csvexport - Force Enclosures

I have been using extension csvexport for a few weeks now and it works very well for me especially exporting large data sets.

One of the fields in my output now contains data in the format of ‘+1234+123456789’. Users downloading this into excel find it gets automatically formatted as a SUM and the values get added together. Enclosing the field with quotes would stop this but making it happen was not straightforward. This field and a few others did not have enclosures although a value of ‘"’ for enclosures was specified and is the default value. Pure text fields were OK but fields containing text and numbers or other characters were not.

I found no matter what I changed in the extension I was unable to FORCE enclosures on all fields. Even when I hard coded the enclosure value in the call to fputcsv.

It turns out fputcsv makes its own decision on whether or not to use enclosures.

If you need to force enclosures the answer is to replace fputcsv with your own function as described in the following example.

"stackoverflow.com/questions/2514597/php-fputcsv-and-enclosing-fields"

(I cannot embed the link in this post.)