Friday, June 12, 2026
HomeLanguagesPHP mb_strlen() Function

PHP mb_strlen() Function

The mb_strlen() is an inbuilt PHP function that returns the string length in an integer.

Syntax:

mb_strlen($string, $encoding ): int

Parameters: This function accepts 2 parameters that are described below:

  • $string: The string parameter whose lengths need to be determined. It is a required parameter.
  • $encoding: It is an optional parameter. This parameter described which type of encoding you are using in the string parameter. Here, the encoding parameter denotes the character encoding. In case if omitted or null, then the internal character encoding value will be utilized.

Return Values: The number of characters in the string that have the character encoding, will be returned by this function. It will count as 1 for the multi-byte character.

Example 1: The following program demonstrates the mb_strlen() function.

PHP




<?php
$str = "안녕하세요";
$length = mb_strlen($str, 'UTF-8');
echo "The length of the string is $length";   
?>


Output:

The length of the string is 5  

Example 2: The following program demonstrates the mb_strlen() function.

PHP




<?php
$str = "neveropen";
$length = mb_strlen($str);
echo "The length of the string is $length";
?>


Output:

The length of the string is 13

Reference: https://www.php.net/manual/en/function.mb-strlen.php

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS