src/Str.php
public static function truncate($input, $limit, $continuation = '...', $isHtml = false)
    {
        $offset = 0;
        $tags = [];
        if ($isHtml) {
            $input = static::truncateHtml($input, $limit, $offset, $tags);
        }

        $newString = static::sub($input, 0, $limit = min(static::length($input), $limit + $offset));
        $newString .= (static::length($input) > $limit ? $continuation : '');
        $newString .= count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : '';

        return $newString;
    }
public static function truncate($input, $limit, $continuation = '...', $isHtml = false)
    {
        $offset = 0;
        $tags = [];
        if ($isHtml) {
            $input = static::truncateHtml($input, $limit, $offset, $tags);
        }

        $newString = static::sub($input, 0, $limit = min(static::length($input), $limit + $offset));
        $newString .= (static::length($input) > $limit ? $continuation : '');
        $newString .= count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : '';

        return $newString;
    }
public static function truncate ( $ input , $ limit , $ continuation = '...' , $ isHtml = false ) { $ offset = 0 ; $ tags = [ ] ; if ( $ isHtml ) { $ input = static :: truncateHtml ( $ input , $ limit , $ offset , $ tags ) ; } $ newString = static :: sub ( $ input , 0 , $ limit = min ( static :: length ( $ input ) , $ limit + $ offset ) ) ; $ newString .= ( static :: length ( $ input ) > $ limit ? $ continuation : '' ) ; $ newString .= count ( $ tags = array_reverse ( $ tags ) ) ? '</' . implode ( '></' , $ tags ) . '>' : '' ; return $ newString ; }
Truncates a string to the given length.

Truncates a string to the given length. It will optionally preserve HTML tags if $is_html is set to true.

@author  FuelPHP (http://fuelphp.com)

@param   string $input        The string to truncate.
@param   int    $limit        The number of characters to truncate to.
@param   string $continuation The string to use to denote it was truncated
@param   bool   $isHtml       Whether the string has HTML

@return  string  The truncated string
@SuppressWarnings(PHPMD.BooleanArgumentFlag)
Truncates a string to the given length .