mirror of
https://github.com/php/php-src.git
synced 2026-03-24 16:22:37 +01:00
fputcsv does not terminate lines correctly as per RFC 41801[1]. After adding a new parameter fputcsv may now use a user defined line ending,. In order to maintain backwards compatibility fputcsv() still terminates lines with "\n" by default. Also fixes: #46367[2], #62770[3] Ref: #42357[4] [1] <https://tools.ietf.org/html/rfc4180> [2] <https://bugs.php.net/bug.php?id=46367> [3] <https://bugs.php.net/bug.php?id=62770> [4] <https://bugs.php.net/bug.php?id=42357>
33 lines
696 B
PHP
33 lines
696 B
PHP
--TEST--
|
|
SplFileObject::fputcsv() with user provided eol
|
|
--FILE--
|
|
<?php
|
|
$data = [
|
|
['aaa', 'bbb', 'ccc', 'dddd'],
|
|
['123', '456', '789'],
|
|
['"aaa"', '"bbb"'],
|
|
];
|
|
|
|
$eol_chars = ['||', '|', '\n', "\n"];
|
|
foreach ($eol_chars as $eol_char) {
|
|
$file = new SplTempFileObject;
|
|
foreach ($data as $record) {
|
|
$file->fputcsv($record, ',', '"', '', $eol_char);
|
|
}
|
|
|
|
$file->rewind();
|
|
foreach ($file as $line) {
|
|
echo $line;
|
|
}
|
|
|
|
echo "\n";
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
aaa,bbb,ccc,dddd||123,456,789||"""aaa""","""bbb"""||
|
|
aaa,bbb,ccc,dddd|123,456,789|"""aaa""","""bbb"""|
|
|
aaa,bbb,ccc,dddd\n123,456,789\n"""aaa""","""bbb"""\n
|
|
aaa,bbb,ccc,dddd
|
|
123,456,789
|
|
"""aaa""","""bbb"""
|