How can you check if a specific word, like "auto", appears in a string using PHP?

To check if a specific word, like "auto", appears in a string using PHP, you can use the strpos() function. This function searches for the occurrence of a specific word within a string and returns the position of the first occurrence if found. If the word is not found, it returns false. You can then use a conditional statement to determine if the word exists in the string.

$string = "This is an example string containing the word auto.";
$word = "auto";

if(strpos($string, $word) !== false) {
    echo "The word '$word' was found in the string.";
} else {
    echo "The word '$word' was not found in the string.";
}