How can you count the occurrence of specific characters in a string in PHP?

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

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