Why does PHP return wrong number of characters of strings with ñ or tildes? How to solve it?

For a while I’ve been amazed that PHP was giving me the wrong number of characters in a string with strlen(). Then I realized that it had the letter “ñ”.

echo strlen(‘nail’) // output 4

Continuing with my tests, I see that it also happens when the letters have accents, any accented letter or, for example, the “ç”.

echo strlen(‘á’) // display 2

Why is this happening? How can I display the correct number of characters?

See also  Gimp and Photoshop
Loading Facebook Comments ...
Loading Disqus Comments ...