Fix order, escape quotes first or the field delimiters get doubled

This commit is contained in:
Nathan Gray 2010-12-17 16:59:02 +00:00
parent 855c601f98
commit 726798c8cb

View File

@ -1172,11 +1172,14 @@ class nextmatch_widget
} }
$value = implode(', ',$value); $value = implode(', ',$value);
if (strpos($value,'"') !== false)
{
$value = '"'.str_replace('"', '""', $value).'"'; // Escape double quotes
}
if (strpos($value,$separator) !== false || strpos($value,"\n") !== false || strpos($value,"\r") !== false) if (strpos($value,$separator) !== false || strpos($value,"\n") !== false || strpos($value,"\r") !== false)
{ {
$value = '"'.str_replace(array('\\','"'),array('\\\\','\\"'),$value).'"'; $value = '"'.str_replace(array('\\','"'),array('\\\\','\\"'),$value).'"';
// to avoid early linebreak by Excel, escape double quotes in text $value = str_replace("\r\n", "\n", $value); // to avoid early linebreak by Excel
$value = str_replace(array("\r\n", '"'), array("\n",'""'), $value);
} }
$out[] = $value; $out[] = $value;
} }