Home

mbstrlen

mbstrlen is commonly used to refer to the multibyte string length function mb_strlen, which is provided by the mbstring extension in PHP. It counts the number of characters in a string rather than the number of bytes by interpreting the string according to a specified character encoding.

The function counts characters according to the given encoding. If no encoding is supplied, mb_strlen uses the

Syntax: mb_strlen(string $string, string|null $encoding = null)

Parameters: $string is the input string. $encoding is an optional encoding name, such as 'UTF-8', 'ISO-8859-1', or

Return value: The function returns an integer representing the number of characters in the string for the

Examples: mb_strlen('hello', 'UTF-8') returns 5. mb_strlen('こんにちは', 'UTF-8') returns 5, illustrating its multibyte awareness.

Notes: mb_strlen counts code points (characters) for the specified encoding, not grapheme clusters. For grapheme-aware length,

See also: strlen, mb_strpos, mb_substr, mb_strwidth, mb_detect_encoding.

internal
encoding
configured
for
mbstring.
This
makes
it
suitable
for
strings
containing
multibyte
characters
such
as
UTF-8,
where
a
single
character
may
occupy
multiple
bytes.
others
supported
by
mbstring.
If
encoding
is
omitted,
the
internal
mbstring
encoding
is
used.
specified
encoding.
If
the
string
contains
invalid
byte
sequences
for
the
given
encoding
or
another
error
occurs,
the
function
may
return
false
or
emit
a
warning
depending
on
the
runtime
configuration.
additional
libraries
or
techniques
may
be
required.
mb_strlen
is
part
of
the
mbstring
extension
and
requires
it
to
be
enabled
in
the
PHP
installation.