LaravelBook\Laravel4Powerpack\Str::words PHP Method

words() public method

Returns "This is a..." echo Str::words('This is a sentence.', 3); Limit the number of words and append a custom ending echo Str::words('This is a sentence.', 3, '---');
public words ( string $value, integer $words = 100, string $end = '...' ) : string
$value string
$words integer
$end string
return string
    public function words($value, $words = 100, $end = '...')
    {
        if (trim($value) == '') {
            return '';
        }
        preg_match('/^\\s*+(?:\\S++\\s*+){1,' . $words . '}/u', $value, $matches);
        if ($this->length($value) == $this->length($matches[0])) {
            $end = '';
        }
        return rtrim($matches[0]) . $end;
    }