How can we check a string containing a specific word in Laravel

How can we check a string containing a specific word in Laravel

how can we check a string containing a specific word in Laravel, Laravel provides a lot of features one of the best features is to find some words from a string or article. Laravel provides us with a method Str which we use to find a specific word and more than one word.

In this article, we will see how to use the str method to find a specific word and more than one word. Here is the example step-by-step.

Example: find a word

Syntax:

Str::contains($string, $finding_word);

Example:

use Illuminate\Support\Str;
$finder = Str::contains('Welcome to theskillstock', 'theskillstock');

Example: Find multiple words

Syntax:

Str::contains($string, [$finding_word, $finding_word2]);

Example:

use Illuminate\Support\Str;
$finder = Str::contains('Hello! Welcome to theskillstock', ['Hello!', 'theskillstock']);

Thank you for reading this article. I hope it is helpful to you.

Comments

No Comment posted Yet!

Leave a Reply

OK! You can skip this field.