Skip to content

Commit

Permalink
Removing double spaces and new lines from CSV
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sanasol authored Jan 12, 2017
1 parent d000cab commit ffec129
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Component/CsvExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit ffec129

Please sign in to comment.