English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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
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.
strlen(string[, string $encoding = mb_internal_encoding() ]))
mb_internal_encoding() is used for setting/Get the internal character encoding.
Parameters | Description |
---|---|
string | Required. Specify the string to be checked. |
encoding | Optional. Character encoding. If omitted, the internal character encoding is used. |
Return value: | If successful, it returns the length of the string; if the string is empty, it returns 0. |
---|---|
PHP Version: | 4+ |