src/Utilities/Miscellaneous.php
public static function substringToWord($text, $maxLength, $suffix = '...')
    {
        $effect = $text;

        $textLength = mb_strlen($text, 'utf-8');
        $suffixLength = mb_strlen($suffix, 'utf-8');

        $maxLength -= $suffixLength;

        if ($textLength > $maxLength) {
            $effect = mb_substr($text, 0, $maxLength, 'utf-8');
            $lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');

            if (false !== $lastSpacePosition) {
                $effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
            }

            $effect .= $suffix;
        }

        return $effect;
    }
public static function substringToWord($text, $maxLength, $suffix = '...')
    {
        $effect = $text;

        $textLength = mb_strlen($text, 'utf-8');
        $suffixLength = mb_strlen($suffix, 'utf-8');

        $maxLength -= $suffixLength;

        if ($textLength > $maxLength) {
            $effect = mb_substr($text, 0, $maxLength, 'utf-8');
            $lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8');

            if (false !== $lastSpacePosition) {
                $effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8');
            }

            $effect .= $suffix;
        }

        return $effect;
    }
public static function substringToWord ( $ text , $ maxLength , $ suffix = '...' ) { $ effect = $ text ; $ textLength = mb_strlen ( $ text , 'utf-8' ) ; $ suffixLength = mb_strlen ( $ suffix , 'utf-8' ) ; $ maxLength -= $ suffixLength ; if ( $ textLength > $ maxLength ) { $ effect = mb_substr ( $ text , 0 , $ maxLength , 'utf-8' ) ; $ lastSpacePosition = mb_strrpos ( $ effect , ' ' , 'utf-8' ) ; if ( false !== $ lastSpacePosition ) { $ effect = mb_substr ( $ effect , 0 , $ lastSpacePosition , 'utf-8' ) ; } $ effect .= $ suffix ; } return $ effect ; }
Returns part of string preserving words

@param string $text      The string / text
@param int    $maxLength Maximum length of given string
@param string $suffix    (optional) The suffix to add at the end of string
@return string
Returns part of string preserving words