public static function escapeText($text, $addApostrophes = true)
    {
        $dangers      = array('\\', '"', "\n");
        $replacements = array('\\\\', '\\"', '\\n');
        $escapedText  = str_ireplace($dangers, $replacements, $text);
        if ($addApostrophes) {
            $escapedText = '"' . $escapedText . '"';
        }
        return $escapedText;
    }