Skip to content

Patch for /trunk/parsecsv.lib.php, fixing CSV output on Windows in save() #27

Description

@GoogleCodeExporter
I've adjusted the write-modes in save($file, $data, $append, $fields) to be 
'ab' and 'wb' instead of 'at' and 'wt'. The reason behind this change is that 
PHP, with the mode of t, will replace \n with \r\n on Windows. We are already 
appending \r\n to the end of our lines, in unparse(), however. Unfortunately, 
this means that our line endings go from \r\n to \r\r\n on Windows, resulting 
in an additional line. Changing $linefeed to \n does not solve the problem. The 
php docs for fopen() also suggest using binary mode for portability across 
platforms.

I have tested this fix with PHP 5.4.9 on OS X (10.7.5), Fedora (12), and on 
Windows 8, and the outputted CSV files are valid, with the correct number of 
lines.

Original issue reported on code.google.com by kolnst...@gmail.com on 27 Dec 2012 at 6:49

Attachments:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions