Easy Tutorial
❮ Php Form Validation Func Error User Error ❯

PHP mb_strlen() Function

PHP String Reference Manual

Example

The function returns the length of the string "tutorialpro.orgtutorialpro":

<?php
// Using mb_strlen
echo mb_strlen("tutorialpro.orgtutorialpro");

echo PHP_EOL; // Newline character

// Using strlen
echo strlen("tutorialpro.orgtutorialpro");
?>

The output is:

10
18

Definition and Usage

The mb_strlen() function returns the length of a string. Unlike strlen, it can return the number of characters based on the specified character encoding, effectively handling the length of Chinese strings.

Using mb_strlen requires the mbstring extension to be enabled.


Syntax

mb_internal_encoding() is used to set/get the internal character encoding.

Parameter Description
string Required. The string to be checked.
encoding Optional. Character encoding. If omitted, the internal character encoding is used.

Technical Details

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

❮ Php Form Validation Func Error User Error ❯