Added support for DOS double line endings

Fixed GitHub issue #75
This commit is contained in:
Christian Bläul
2018-01-21 17:00:20 +01:00
committed by Fonata
parent 003e98e8ff
commit f41a18b1c0
2 changed files with 13 additions and 1 deletions

View File

@@ -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);

View File

@@ -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";