Req #46367 [Opn->Dup]: fputcsv does not add the correct newline character on Windows
| From: | cmb@php.net | Date: | Mon, 30 Mar 2020 16:58:28 +0000 |
| Subject: | Req #46367 [Opn->Dup]: fputcsv does not add the correct newline character on Windows | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226346@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=46367&edit=1
ID: 46367
Updated by: cmb@php.net
Reported by: jmertic@php.net
Summary: fputcsv does not add the correct newline character
on Windows
-Status: Open
+Status: Duplicate
Type: Feature/Change Request
Package: *General Issues
Operating System: Windows XP
PHP Version: 5.2.6
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Closing as duplicate of bug #42357 (whether it is a bug or a
feature request will yet have to be determined).
Previous Comments:
------------------------------------------------------------------------
[2012-09-19 10:22:44] gtisza at gmail dot com
See https://bugs.php.net/bug.php?id=42357 (add
optional parameter for line ending to fputcsv).
------------------------------------------------------------------------
[2010-03-10 20:41:53] johannes@php.net
Applying the "correct" patch means that the resulting file is system dependent and might
break what current users expect. Probably this needs to be configured (additional parameter?)
------------------------------------------------------------------------
[2010-03-10 19:50:50] m_rayman at bigfoot dot com
For such a simple bug, this should have been solved the same week it was brought to attention...
The correct and tested patch is even included!
------------------------------------------------------------------------
[2009-07-17 11:41:41] chris dot tatedavies at inflightproductions dot com
How long does the voting last? I need to know if this is going to be fixed. Or if it has been
already. I've looked through the changelog to no avail. Its been over 8 months since the
original report.
Thanks, Chris
------------------------------------------------------------------------
[2008-11-06 13:49:51] jmertic@php.net
Updated earlier patch:
Index: file.c
===================================================================
RCS file: /repository/php-src/ext/standard/file.c,v
retrieving revision 1.530
diff -u -r1.530 file.c
--- file.c 21 Oct 2008 22:06:48 -0000 1.530
+++ file.c 22 Oct 2008 21:21:42 -0000
@@ -2104,7 +2104,7 @@
}
}
- smart_str_appendc(&csvline, '\n');
+ smart_str_appendl(&csvline, PHP_EOL, sizeof(PHP_EOL));
smart_str_0(&csvline);
ret = php_stream_write(stream, csvline.c, csvline.len);
Also below is a test case for this bug. Should fail currently on Windows.
--TEST--
Bug #46367 - fputcsv does not add the correct newline character on Windows
--FILE--
<?php
$array1 = array("a","b","c");
$array2 = array("a","b","c");
$data_file = dirname(__FILE__) . '/dump.txt';
$fp = fopen($data_file);
fputcsv($fp,$array1);
fputcsv($fp,$array2);
fclose($fp);
$csvfile = file_get_contents($data_file);
var_dump(stripos($csvfile,PHP_EOL) !== FALSE);
echo "Done\n";
unlink($data_file);
?>
--EXPECT--
bool(true)
Done
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=46367
--
Edit this bug report at https://bugs.php.net/bug.php?id=46367&edit=1