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

To efficiently count the occurrences of specific characters in a PHP string, you can use the `substr_count()` function. This function takes two parameters - the string to search within and the specific character to count. It returns the number of times the character appears in the string.

$string = "hello world";
$char = "l";
$count = substr_count($string, $char);
echo "The character '$char' appears $count times in the string.";