How to Count Occurrences of a Search String in Laravel
In this lesson, we are going to see how to count occurrences of a search string in Laravel, the substrCount helper method is used to count the number of occurrences of a particular string in a given string.
The Str::substrCount helper method
The substrCount() method is used to count the number of occurrences of a particular string in a given string.
use Illuminate\Support\Str;
$portion = Str::substrCount('Darija Coding', 'Coding');
echo $portion;
// Returns "1"