summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCraig Duncan <git@duncanc.co.uk>2014-12-09 16:00:49 +0000
committerCraig Duncan <git@duncanc.co.uk>2014-12-09 16:32:24 +0000
commit530b93665c723c2d500522dc31586ffa39a43de3 (patch)
tree975f55d017376461e79136241ad03fea55d959b8 /src
parent25198fd4036de1b5d46447ae2382fdafd86bade9 (diff)
downloadcsv-530b93665c723c2d500522dc31586ffa39a43de3.zip
csv-530b93665c723c2d500522dc31586ffa39a43de3.tar.gz
csv-530b93665c723c2d500522dc31586ffa39a43de3.tar.bz2
Allow the line ending characters to be overridden
Diffstat (limited to 'src')
-rw-r--r--src/AbstractCsv.php1
-rw-r--r--src/Config/Controls.php31
-rw-r--r--src/Writer.php5
3 files changed, 37 insertions, 0 deletions
diff --git a/src/AbstractCsv.php b/src/AbstractCsv.php
index 5c30036..0986f18 100644
--- a/src/AbstractCsv.php
+++ b/src/AbstractCsv.php
@@ -218,6 +218,7 @@ abstract class AbstractCsv implements JsonSerializable, IteratorAggregate
{
$csv = new $class_name($this->path, $open_mode);
$csv->delimiter = $this->delimiter;
+ $csv->lineEnding = $this->lineEnding;
$csv->enclosure = $this->enclosure;
$csv->escape = $this->escape;
$csv->encodingFrom = $this->encodingFrom;
diff --git a/src/Config/Controls.php b/src/Config/Controls.php
index 8eba624..7147d4d 100644
--- a/src/Config/Controls.php
+++ b/src/Config/Controls.php
@@ -34,6 +34,13 @@ trait Controls
protected $delimiter = ',';
/**
+ * the line ending
+ *
+ * @var string
+ */
+ protected $lineEnding = "\n";
+
+ /**
* the field enclosure character (one character only)
*
* @var string
@@ -91,6 +98,30 @@ trait Controls
}
/**
+ * set the line ending
+ *
+ * @param string $lineEnding
+ *
+ * @return $this
+ */
+ public function setLineEnding($lineEnding = "\n")
+ {
+ $this->lineEnding = $lineEnding;
+
+ return $this;
+ }
+
+ /**
+ * return the current line ending
+ *
+ * @return string
+ */
+ public function getLineEnding()
+ {
+ return $this->lineEnding;
+ }
+
+ /**
* detect the actual number of row according to a delimiter
*
* @param string $delimiter a CSV delimiter
diff --git a/src/Writer.php b/src/Writer.php
index 4370bc7..9049bba 100644
--- a/src/Writer.php
+++ b/src/Writer.php
@@ -195,6 +195,11 @@ class Writer extends AbstractCsv
}
$this->getCsv()->fputcsv($data, $this->delimiter, $this->enclosure);
+ if ($this->lineEnding !== "\n") {
+ $this->getCsv()->fseek(-1, \SEEK_CUR);
+ $this->getCsv()->fwrite($this->lineEnding);
+ }
+
return $this;
}