private function quoteCSV($field)
{
if (!is_scalar($field)) {
$field = json_encode($field);
}
$delimiter_esc = preg_quote(self::CSV_DELIMITER, '/');
$enclosure_esc = preg_quote(self::CSV_ENCLOSURE, '/');
if (preg_match("/(?:{$delimiter_esc}|{$enclosure_esc}|\\s)/", $field)) {
return self::CSV_ENCLOSURE . str_replace(self::CSV_ENCLOSURE, self::CSV_ENCLOSURE . self::CSV_ENCLOSURE, $field) . self::CSV_ENCLOSURE;
} else {
return $field;
}
}