Are there any best practices for efficiently finding the position of a word in a string in PHP?

When trying to find the position of a word in a string in PHP, one efficient way is to use the strpos() function, which returns the position of the first occurrence of a substring within a string. To find the position of a word, you can simply pass the word and the string to strpos().

$word = 'example';
$string = 'This is an example sentence.';
$position = strpos($string, $word);

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