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

To efficiently count the occurrences of a character in a string in PHP, one of the best practices is to use the built-in function `substr_count()`. This function takes two parameters: the string to search in and the character to count. It returns the number of times the specified 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.";