PHP – Get the string length using mb_strlen()

In PHP, multibyte string length (mb_strlen) function is used to get the total string length of a specified string. This function is supported in PHP 4.6.0 or higher versions.


int mb_strlen(str $string, str $encoding)


mb_strlen() accepts two parameters: $string and $encoding.

  • $string− It is used to check the string length

  • $encoding− This parameter is used for character encoding. If it is omitted or null, then the internal character encoding value will be used.

Return Values

mb_strlen() returns the number of characters present in the given string. One is counted as a multi-byte character.


If the encoding is not known, then it will generate the level E_warning.


 Live Demo

   // It will return total number of character
   $result = mb_strlen("Hello World","UTF-8");
   echo "Total number of characters: ", $result;


Total number of characters: 11

Note: that it counts the space too in the given string.