Use the PHP strpos() Function

You can use the PHP strpos() function to check that a string contains a specific word or not.

The strpos() function returns the position of the first look of the substring with the string. If the substring is not found it returns false. Also note that the string positions start at 0, not 1.

Let us appearance at an example to grasp how this function works basically:

Example 1

<?php
$word = "fox";
$string = "The quick brown fox jumps over the lazy dog";
 
// Test if string contains the word 
if(strpos($string , $word) !== false){
    echo "Word Found!";
} else{
    echo "Word Not Found!";
}
?>

Example 2

$str = "Hi, I am from howtowebcode.com";
$result = preg_match("from", $str);
if($result == 1){
	print_r("Yes, exists");
}