public static function toSingleWhitespace($string, $trim = true)
    {
        $string = preg_replace("/\r|\n|\t/", " ", $string);
        $string = preg_replace("/ {2,}/", " ", $string);

        if ($trim) {
            $string = self::trim($string);
        }

        return $string;
    }