Backend Development 2 min read

PHP mb_substr() Function: Multibyte‑Safe Substring Operation

This article explains PHP’s mb_substr() function, detailing its multibyte‑safe substring behavior, parameter definitions, return value, and provides a practical code example illustrating how to extract a portion of a Chinese string correctly.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP mb_substr() Function: Multibyte‑Safe Substring Operation

mb_substr() performs a multibyte‑safe substring operation on a string, counting positions from the start (0‑based) and optionally specifying length and encoding.

Parameters

string $str : the input string.

int $start : the starting character position.

int $length = NULL : maximum number of characters to extract; if omitted or NULL, extracts to the end.

string $encoding : character encoding; defaults to the internal encoding.

Return value

The function returns the portion of $str defined by $start and $length .

Example

Note

Unlike the regular substr() , mb_substr() correctly handles multibyte characters such as Chinese.

BackendPHPString()substringmb_substrMultibyte
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.