diff --git a/parsecsv.lib.php b/parsecsv.lib.php index 790df4a..7c9012d 100644 --- a/parsecsv.lib.php +++ b/parsecsv.lib.php @@ -418,7 +418,7 @@ class parseCSV { $file = &$this->file; } - $mode = $append ? 'at' : 'wt'; + $mode = $append ? 'ab' : 'wb'; $is_php = preg_match('/\.php$/i', $file) ? true : false; return $this->_wfile($file, $this->unparse($data, $fields, $append, $is_php), $mode); diff --git a/tests/methods/SaveTest.php b/tests/methods/SaveTest.php index d871975..4780b87 100644 --- a/tests/methods/SaveTest.php +++ b/tests/methods/SaveTest.php @@ -32,6 +32,18 @@ class SaveTest extends PHPUnit\Framework\TestCase { $this->saveAndCompare($expected); } + public function testSaveWithDosLineEnding() { + $this->csv->linefeed = "\r\n"; + $expected = "SMS\r\n0444\r\n5555\r\n"; + $this->saveAndCompare($expected); + } + + public function testSaveWithUnixLineEnding() { + $this->csv->linefeed = "\n"; + $expected = "SMS\n0444\n5555\n"; + $this->saveAndCompare($expected); + } + public function testAllQuotes() { $this->csv->enclose_all = true; $expected = "\"SMS\"\r\"0444\"\r\"5555\"\r";