src/Strings.php
public function limitWords($string, $limit = false, $end = '...')
    {
        $words = explode(" ", $string);

        if (count($words) <= $limit) {
            return $string;
        }

        $return = [];
        for ($wordCount = 0; $wordCount < $limit; $wordCount++) {
            $return[] = $words[$wordCount];
        }

        $return[] = $end;

        return implode(" ", $return);
    }
public function limitWords($string, $limit = false, $end = '...')
    {
        $words = explode(" ", $string);

        if (count($words) <= $limit) {
            return $string;
        }

        $return = [];
        for ($wordCount = 0; $wordCount < $limit; $wordCount++) {
            $return[] = $words[$wordCount];
        }

        $return[] = $end;

        return implode(" ", $return);
    }
public function limitWords ( $ string , $ limit = false , $ end = '...' ) { $ words = explode ( " " , $ string ) ; if ( count ( $ words ) <= $ limit ) { return $ string ; } $ return = [ ] ; for ( $ wordCount = 0 ; $ wordCount < $ limit ; $ wordCount ++ ) { $ return [ ] = $ words [ $ wordCount ] ; } $ return [ ] = $ end ; return implode ( " " , $ return ) ; }
Limits a string to a certain number of words

@param string $string
@param int $limit
@param string $end
@return string
Limits a string to a certain number of words