From ffec129cc513dd15cf1ff494222f44e3b56e3ab7 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 12 Jan 2017 15:20:46 +0700 Subject: [PATCH] Removing double spaces and new lines from CSV Need do some string cleanup. Remove >1 spaces and all new lines, trailing spaces. To avoid incorrect display in Excel/Calc columns after html code stripping. OO Calc: http://dsro.ru/gyazo/images/046186fb43d10e6092e05b7fbfab.png MS Excel: http://dsro.ru/gyazo/images/c20a37008265555a18f7ccf55e99.png --- src/Component/CsvExport.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Component/CsvExport.php b/src/Component/CsvExport.php index 0959160..d173640 100644 --- a/src/Component/CsvExport.php +++ b/src/Component/CsvExport.php @@ -154,7 +154,12 @@ protected function renderCsv() protected function escapeString($str) { - return str_replace('"', '\'', strip_tags(html_entity_decode($str))); + $str = html_entity_decode($str); + $str = strip_tags($str); + $str = str_replace('"', '\'', $str); + $str = preg_replace('/\s+/', ' ', $str); + $str = trim($str); + return $str; } /**