Number of characters

You can find out the number of characters in a string using the function mb_strlen().

mb_strlen('php'); // 3

Special characters (such as "\n") count as one character.

mb_strlen("\n"); // 1

For the strlen() function, , it is recommended to specify the encoding "utf-8", otherwise it will return the number of bytes, not characters.

strlen('»');          // 2 (although the symbol is 1)
strlen('»', 'utf-8'); // 1