public function escape($string, $preserveEntities = false)
{
if ($preserveEntities) {
$string = preg_replace('/[&](?![#](x[a-f0-9]{1,8}|[0-9]{1,8});|[a-z][a-z0-9]{1,31};)/i', '&', $string);
} else {
$string = str_replace('&', '&', $string);
}
return str_replace(['<', '>', '"'], ['<', '>', '"'], $string);
}