Skip to content

Commit

Permalink
Add better support for newlines in CSV serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Sep 9, 2019
1 parent 2f8d0b0 commit 06c839c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,13 @@ public static function serializeRow(array $value, array $omit = [], $delimiter =
$rowAry = [];
foreach ($value as $key => $val) {
if (!in_array($key, $omit)) {
$val = str_replace(["\n", "\r"], [" ", " "], $val);
if (strpos($val, $delimiter) !== false) {
if (strpos($val, $enclosure) !== false) {
$val = str_replace($enclosure, $escape . $enclosure, $val);
}
$val = $enclosure . $val . $enclosure;
} else if (strpos($val, "\n") !== false) {
$val = $enclosure . $val . $enclosure;
}
$rowAry[] = $val;
}
Expand Down

0 comments on commit 06c839c

Please sign in to comment.