src/Xiphe/THEWPTOOLS.php
public static function shorten($text, $maxlength = 140, $end = '[...]') {
        $maxlength++;
        if (mb_strlen($text) > $maxlength) {
            $subex = mb_substr($text, 0, $maxlength - 5);
            $exwords = explode(' ', $subex);
            $excut = - (mb_strlen($exwords[count($exwords)-1]));
            if ($excut < 0) {
                $text = mb_substr($subex, 0, $excut);
            } else {
                $text = $subex;
            }
            $text .= $end;
        }
        return $text;
    }
public static function shorten($text, $maxlength = 140, $end = '[...]') {
        $maxlength++;
        if (mb_strlen($text) > $maxlength) {
            $subex = mb_substr($text, 0, $maxlength - 5);
            $exwords = explode(' ', $subex);
            $excut = - (mb_strlen($exwords[count($exwords)-1]));
            if ($excut < 0) {
                $text = mb_substr($subex, 0, $excut);
            } else {
                $text = $subex;
            }
            $text .= $end;
        }
        return $text;
    }
public static function shorten ( $ text , $ maxlength = 140 , $ end = '[...]' ) { $ maxlength ++ ; if ( mb_strlen ( $ text ) > $ maxlength ) { $ subex = mb_substr ( $ text , 0 , $ maxlength - 5 ) ; $ exwords = explode ( ' ' , $ subex ) ; $ excut = - ( mb_strlen ( $ exwords [ count ( $ exwords ) - 1 ] ) ) ; if ( $ excut < 0 ) { $ text = mb_substr ( $ subex , 0 , $ excut ) ; } else { $ text = $ subex ; } $ text .= $ end ; } return $ text ; }
Builds an excerpt from a longer text.

@param string  $text      the input text
@param integer $maxlength maximal length of the text
@param string  $end       a string that will be attached to the short version of $text

@return string
Builds an excerpt from a longer text .