What are some common pitfalls when trying to count the occurrences of a character in a string in PHP?

One common pitfall when trying to count the occurrences of a character in a string in PHP is not accounting for case sensitivity. If you want to count both uppercase and lowercase occurrences of a character, you need to make sure your comparison is case-insensitive. Another pitfall is not properly handling multibyte characters, which can result in inaccurate counts. To solve these issues, you can use the `mb_substr_count()` function in PHP, which handles multibyte characters and allows for case-insensitive counting.

$string = "Hello World";
$character = 'o';

$count = mb_substr_count(strtolower($string), strtolower($character));

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