Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP mb_strlen() Function

PHP mb_strlen() Function

PHP String Reference Manual PHP String Reference Manual

Example

The function returns the length of the string "Runoob TutorialRUNOOB":

The output is:



10

18


Definition and Usage

The mb_strlen() function returns the length of a string, unlike strlen which can return the corresponding number of characters by setting the character encoding, handling the length of Chinese strings well.

Using mb_strlen requires the mbstring extension to be enabled.


Syntax



mb_strlen(string $string, ?string $encoding = null): int

mb_strlen() is used to get the string length.

Parameters Description
string Required. Specifies the string to check.
encoding Optional. The character encoding. If omitted, the internal character encoding is used.

Technical Details

Return Value: Returns the length of the string on success, or 0 if the string is empty.
PHP Version: 4+

PHP String Reference Manual PHP String Reference Manual