What are some best practices for efficiently counting the occurrences of a specific word in a string using PHP?

When counting the occurrences of a specific word in a string in PHP, one efficient approach is to use the `substr_count()` function. This function takes two parameters - the string to search in and the word to count occurrences of. By using this function, you can easily determine the number of times a specific word appears in a given string.

$string = "This is a sample string to demonstrate counting occurrences of the word 'sample' in PHP.";
$word = "sample";

$occurrences = substr_count($string, $word);

echo "The word '$word' appears $occurrences times in the string.";