PHP Laravel – How to Check if a String Contains a Specific Word?

PHP Laravel – How to Check if a String Contains a Specific Word?

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

This example will help you to check if a string contains any substring in laravel. you can check if url contains string in laravel using Str::contains(). i will give you simple example of laravel str contains case insensitive.

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 IlluminateSupportStr;

$myString = 'This is from onlinecode website.';

$contains = Str::contains($myString, 'onlinecode');

// true

With Multiple Words Contains:

Also see:Laravel Redirect to URL using redirect() helper

use IlluminateSupportStr;

$myString = 'This is from onlinecode website.';

$contains = Str::contains($myString, ['onlinecode', 'website']);

// true

You can use easily with your controller method.

I hope it can help you….

Hope this code and post will helped you for implement PHP Laravel – How to Check if a String Contains a Specific Word?. 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

Leave a Comment

Your email address will not be published. Required fields are marked *

5  +  2  =  

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