OKyJIucT
8/17/2016 - 1:38 PM

Обрезаем текст

Обрезаем текст

/**
 * Обрезаем строку
 *
 * @param $string
 * @param int $length
 * @return string
 */
public static function cut($string, $length = 400)
{
    if (mb_strlen($string) < $length)
        return $string;
    $string = strip_tags($string);
    $string = mb_substr($string, 0, $length);
    $string = rtrim($string, "!,.-");
    $string = mb_substr($string, 0, strrpos($string, ' '));

    return $string . "...";
}