HDTuto.com

How to Check If a String Contains a Specific Word in Laravel?



In this post, we will learn if string contains laravel. step by step explain check if string contains substring php laravel. This post will give you simple example of laravel str contains case insensitive example. This tutorial will give you simple example of laravel check string contains.

Laravel has a Str helper function. Str class has contains() method that will provide to check string contains in laravel application. contains() take a two argument one should be string and another will be string or array.

I will give you both example so you can easily use in your controller method. so let's see bellow both example will help you to use.

With Single Word Contains:

use Illuminate\Support\Str;

$myString = 'This is from itsolutionstuff.com website.';

$contains = Str::contains($myString, 'itsolutionstuff.com');

// true

With Multiple Words Contains:

use Illuminate\Support\Str;

$myString = 'This is from itsolutionstuff.com website.';

$contains = Str::contains($myString, ['itsolutionstuff.com', 'website']);

// true

You can use easily with your controller method.

I hope it can help you....




May 3, 2020 | Category : Laravel



Blog Search


Copyright © 2020 HDTuto.com. All rights reserved.