Файл: vsime.com/system/functions/str_cut.php
Строк: 17
<?php
    function str_cut($text, $maxwords = 10, $maxchar = 30)
    {
        $new_text = NULL;
        if (count(explode(" ", $text)) > $maxwords) {
            $array_words = explode(" ", $text);
            $i = 0;
            foreach ($array_words AS $key => $value) {
                $i++;
                $new_text .= ' '.$value;
                if ($i > $maxwords)break;
            }
        }
        if (!$new_text)$new_text = $text;
        if (strlen2($new_text) > $maxchar) {
            $array_chars = str_split($new_text);
            $new_text = NULL;
            $i = 0;
            foreach ($array_chars AS $key => $value) {
                $i++;
                $new_text .= $value;
                if ($i > $maxchar)break;
            }
        }
        if ($new_text != $text)$new_text.= '...';
        return $new_text;
    }
?>