Backend Development 2 min read

PHP mb_substr Function: Multibyte‑Safe Substring Extraction

This article explains the PHP mb_substr() function, detailing its multibyte‑safe substring behavior, parameter list (str, start, length, encoding), return value, and provides a clear example showing how to extract the first two characters from a Chinese string.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP mb_substr Function: Multibyte‑Safe Substring Extraction

The PHP mb_substr() function retrieves a portion of a string in a multibyte‑safe manner.

It counts positions from the start of the string, with the first character at index 0, the second at 1, and so on.

Signature:

string mb_substr(string $str, int $start[, int $length = NULL[, string $encoding = mb_internal_encoding()]])

Parameters:

str : the source string.

start : the position of the first character to include.

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

encoding : character encoding; defaults to the internal encoding if omitted.

Return value: the extracted substring according to the given start and length.

Example:

backendphpString()functionmb_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.