English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP mb_strlen() Function Usage and Examples

PHP String Reference Manual

Online Examples

The function returns the string "Basic Tutorial Website w3The length of codebox" is:

<?php
// Using mb_strlen
echo mb_strlen("Basic Tutorial Website w3codebox");
 
echo PHP_EOL; // Newline character
 
// Using strlen
echo strlen("Basic Tutorial Website w3codebox");
?>
Test and see ‹/›

The output result is:

10
20

Definition and Usage

The mb_strlen() function returns the length of the string, similar to strlen At different times, it can return the corresponding character count by setting the character encoding, which handles the length problem of Chinese string very well.

To use mb_strlen, the mbstring extension must be enabled.

Syntax

strlen(string[, string $encoding = mb_internal_encoding() ]))

mb_internal_encoding() is used for setting/Get the internal character encoding.

ParametersDescription
stringRequired. Specify the string to be checked.
encodingOptional. Character encoding. If omitted, the internal character encoding is used.

Technical Details

Return value:If successful, it returns the length of the string; if the string is empty, it returns 0.
PHP Version:4+


PHP String Reference Manual