In this tutorial you will learn about the Laravel substrCount() function Example and its application with practical example.
Laravel substrCount() function Example
In this article, I’ll show you how to use laravel substrCount() function with example. We will show example of substrCount() function in laravel. In this tutorial, we will use substrCount() function to count occurrences of a given value in the given string.
Laravel Str::substrCount method
The Str::substrCount method returns the number of occurrences of a given value in the given string
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Controllers\FileController; use Illuminate\Support\Str; class HomeController extends Controller { /** * Show the application dashboard. * * @return \Illuminate\Contracts\Support\Renderable */ public function index() { $c1 = Str::substrCount('If you like ice cream, you will like snow cones.', 'like'); echo $c1."<br>"; $c2 = Str::substrCount('It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.','established'); echo $c2."<br>"; $c3 = Str::substrCount('Li Europan lingues es membres del sam familie.','membres'); echo $c3."<br>"; } } |
Output:-
1 2 3 |
2 1 1 |