Home

mbstring

mbstring is a PHP extension that provides multibyte string handling to support encodings such as UTF-8 and other non‑single-byte character sets. It enables encoding-aware operations on strings, ensuring that characters are not inadvertently split or corrupted during processing.

The extension offers a broad set of functions prefixed with mb_ for common string tasks. Examples include

mbstring relies on a configured internal encoding and can handle a variety of character sets beyond UTF-8.

Installation and configuration vary by platform. mbstring is commonly bundled with PHP and enabled in php.ini

Related topics include Unicode, UTF-8, and multibyte character sets.

mb_strlen
and
mb_substr
for
length
and
substring
operations,
mb_strpos
and
mb_strrpos
for
searching
within
multibyte
strings,
and
mb_strtolower
and
mb_strtoupper
for
case
conversion.
Additional
utilities
cover
string
trimming,
trimming
by
width,
width
calculation,
and
safe
conversion
between
encodings
via
mb_convert_encoding.
It
also
provides
multibyte
regular
expression
support
through
related
functions,
and
facilities
for
detecting
and
configuring
encodings,
such
as
mb_detect_encoding
and
mb_internal_encoding.
Applications
should
explicitly
set
the
internal
encoding
with
mb_internal_encoding
and,
where
necessary,
specify
the
encoding
in
function
calls
to
avoid
ambiguity.
The
extension
often
collaborates
with
other
PHP
encoding
tools,
such
as
iconv,
and
can
be
used
in
conjunction
with
multibyte-aware
regular
expressions.
(for
example,
extension=mbstring.so
on
Unix-like
systems
or
enabling
the
PHP_MBSTRING
module
on
Windows).
On
many
distributions,
it
is
available
as
a
separate
package
(for
instance,
php-mbstring).
Proper
enabling
and
encoding
configuration
are
important
for
correct
operation
across
multilingual
input
and
output.