public function truncate($text, $limit, $isFile = false, $encoding = 'UTF-8')
    {
        $ext = null;
        if ($isFile) {
            $ext = $this->getExt($text);
            if ($ext) {
                $limit -= mb_strlen($ext, $encoding);
                $text = mb_substr($text, 0, -mb_strlen($ext, $encoding) - 1);
            }
        }

        if (mb_strlen($text, $encoding) > $limit) {
            $text = mb_substr($text, 0, $limit - 3, $encoding).'...';
        }

        return $text.($ext ? '.'.$ext : null);
    }
public function truncate($text, $limit, $isFile = false, $encoding = 'UTF-8')
    {
        $ext = null;
        if ($isFile) {
            $ext = $this->getExt($text);
            if ($ext) {
                $limit -= mb_strlen($ext, $encoding);
                $text = mb_substr($text, 0, -mb_strlen($ext, $encoding) - 1);
            }
        }

        if (mb_strlen($text, $encoding) > $limit) {
            $text = mb_substr($text, 0, $limit - 3, $encoding).'...';
        }

        return $text.($ext ? '.'.$ext : null);
    }
public function truncate ( $ text , $ limit , $ isFile = false , $ encoding = 'UTF-8' ) { $ ext = null ; if ( $ isFile ) { $ ext = $ this -> getExt ( $ text ) ; if ( $ ext ) { $ limit -= mb_strlen ( $ ext , $ encoding ) ; $ text = mb_substr ( $ text , 0 , - mb_strlen ( $ ext , $ encoding ) - 1 ) ; } } if ( mb_strlen ( $ text , $ encoding ) > $ limit ) { $ text = mb_substr ( $ text , 0 , $ limit - 3 , $ encoding ) . '...' ; } return $ text . ( $ ext ? '.' . $ ext : null ) ; }
Truncate text to not be too large.

@param string $text   Text to truncate
@param int    $limit  Limit
@param bool   $isFile Indicate if it should be treated as file to keep the extension
@parame string $encoding Encoding to use

@return string Trucnated text
Truncate text to not be too large .