mb_strlen()
mb_strlen() — Get string length.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
mb_strlen(string $string, ?string $encoding = null): int
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The string being checked for length. |
| $encoding | ?string | The encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used. |
Return value
Returns the number of characters in string string having character encoding encoding. A multi-byte character is counted as 1.
Example
The PHP manual ships no example for mb_strlen(); the signature and the parameter table above are the contract.
Changelog
| Version | Change |
|---|---|
| 8.0.0 | encoding is nullable now. |
| 8.0.0 | Now throws a ValueError if encoding is an invalid encoding. Previously, an E_WARNING was emitted and false was returned. |
See also
mb_internal_encoding(), iconv_strlen(), strlen()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page mb_strlen() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.