Laravel substrCount() function Example

Laravel 8 , Laravel 7 , Laravel , Laravel 6

Nicesnippets

750

15-02-2021


Hi Guys,

In this blog,I will you how to use laravel str substrCount() function example. We will show example of substrCount function in laravel.The Str::substrCount method returns the number of occurrences of a given value in the given string:

Here, I will give you full example for simply str substrCount() method in laravel as bellow.

solution


$substrCount = Str::substrCount('Li Europan lingues es membres del sam familie.','membres');

print_r($substrCount);

// output - 4

Example

<?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()

{

$substrCount1 = Str::substrCount('If you like ice cream, you will like snow cones.', 'like');

print_r($substrCount1);

// output - 2

$substrCount2 = 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');

print_r($substrCount2);

// output - 3

$substrCount3 = Str::substrCount('Li Europan lingues es membres del sam familie.','membres');

print_r($substrCount3);

// output - 4

}

}

Output

2

3

4

It Will help you...