How to check if string contains a substring in php ?

In this article, We’ll see how we can check string contains a substring in php.

Below an example if string contains a substring, it will return true otherwise false.




 $string = 'Hello World!';
$substring = 'Hello';

 if (strpos($string, $substring) !== FALSE) {
    echo 'true';
 }
else {
    echo 'false';
 }

That’s it!. Please share your thoughts or suggestions in the comments below.

Leave a Reply

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