[PATCH] Bug #46367 - fputcsv does not add the correct newline character on Windows
| From: | John Mertic | Date: | Wed, 22 Oct 2008 17:03:46 +0000 |
| Subject: | [PATCH] Bug #46367 - fputcsv does not add the correct newline character on Windows | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-41320@lists.php.net to get a copy of this message | ||
Hi All,
My first patch so be gentle :-).
Per the documentation for the fputcsv() function, it adds a newline to
the end of the csv string it returns. However, it is hardcoded to be
'\n' ( default for unix newline ), while Windows uses \r\n. PHP should
do this as well.
Below is a patch to fix this issue; it uses the constant PHP_EOL to get
the correct newline to use on the current platform:
Index: php-src/ext/standard/file.c
===================================================================
RCS file: /repository/php-src/ext/standard/file.c,v
retrieving revision 1.530
diff -r1.530 file.c
2107c2107
< smart_str_appendc(&csvline, '\n');
---
> smart_str_appendc(&csvline, PHP_EOL);
John Mertic
jmertic@gmail.com
http://jmertic.wordpress.com
"Explaining a joke is like dissecting a frog: you understand it
better, but the frog dies
in the process." --Mark Twain