Counting the Number of Words in a String in Laravel 9
In this lesson, we are going to see how to count the number of words in a string in Laravel 9, there is a helper that counts the number of words that contains a provided string.
The Str::wordCount helper method
The wordCount() method returns the number of words that a provided string contains.
use Illuminate\Support\Str;
Str::wordCount('Hello, world!'); // 2