Are there best practices for efficiently counting specific values within a string in PHP?

When counting specific values within a string in PHP, a common and efficient approach is to use the `substr_count()` function. This function allows you to count the number of occurrences of a specific substring within a given string.

$string = "hello world hello";
$substring = "hello";
$count = substr_count($string, $substring);

echo "The substring '$substring' appears $count times in the string.";