public function truncate($str, $length, $ellipsis = '...')
    {
        $result = '';
        foreach (preg_split('/\b/U', $str) as $part) {
            if (strlen($result . $part) > $length) {
                $result = rtrim($result) . $ellipsis;
                break;
            } else {
                $result .= $part;
            }
        }

        return $result;
    }