Check if String Contains Specific Word in Laravel

How To Check if String Contains Specific Word in Laravel

How To Check if String Contains Specific Word in Laravel

In this post, we will give you information about How To Check if String Contains Specific Word in Laravel. Hear we will give you detail about How To Check if String Contains Specific Word in Laravel And how to use it also give you a demo for it if it is necessary.

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

How To Check if String Contains Specific Word in Laravel

Syntax

Str::contains($content, $find)

In the contains function, the First argument is a string that you want to check from. And the second argument is to check that specific word.

Example for Check if String Contains Specific Word in Laravel

use IlluminateSupportStr;
 
$contains = Str::contains('Hello World', 'World');

// true

You can also pass an array of values to see if any of the values in the array are contained in the given string.

 Syntax

Str::contains($content, [$firstWord, $secondWord])

Example for Check if String Contains Specific Word in Laravel

use IlluminateSupportStr;
 
$contains = Str::contains('Hello World', ['Hello', 'Bar']);

// true

You can also pass an array of values to see if all values in the array are contained in the given string.

Example for Check if String Contains Specific Word in Laravel

use IlluminateSupportStr;
 
$contains = Str::containsAll('Hello Laravel World', ['Hello', 'World']);

// true

Thank you for reading Check if String Contains Specific Word in Laravel article, Hope this code and post will helped you for implement How To Check if String Contains Specific Word in Laravel. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US