public function quote($string)
{
$string = str_replace("", '', $string);
$hasSingleQuote = FALSE !== strpos($string, "'");
if ($hasSingleQuote) {
$hasDoubleQuote = FALSE !== strpos($string, '"');
if ($hasDoubleQuote) {
$result = '';
preg_match_all('("[^\']*|[^"]+)', $string, $matches);
foreach ($matches[0] as $part) {
$quoteChar = substr($part, 0, 1) === '"' ? "'" : '"';
$result .= ", " . $quoteChar . $part . $quoteChar;
}
return 'concat(' . substr($result, 2) . ')';
} else {
return '"' . $string . '"';
}
} else {
return "'" . $string . "'";
}
}