Published in Laravel

Laravel String Helper Function: words

By John Koster

The words helper method is similar to the limit function, but instead of limiting the number of characters returned, it limits the number of words returned.

The signature for the words helper function is:

words($value, $words = 100, $end = '...')

1use Illuminate\Support\Str;
2
3// Hello everyone...
4echo Str::words('Hello everyone out there!', '2);