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.
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:
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.