Backend Development 3 min read

Using mb_strcut() to Extract Substrings by Bytes in PHP

This article explains how the PHP mb_strcut() function extracts a substring based on byte positions, compares it with mb_substr() and substr(), details its parameters and return value, and provides a complete example demonstrating byte‑level string cutting for multibyte text.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Using mb_strcut() to Extract Substrings by Bytes in PHP

mb_strcut() – Getting a Portion of a String by Bytes

The mb_strcut() function extracts a substring from a string based on byte positions, similar to mb_substr() but operates on bytes rather than characters, preventing malformed byte sequences that substr() may produce.

Parameters

str : The input string to be cut.

start : Starting position in bytes.

length : Byte length to extract; if omitted or NULL , extracts to the end.

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

Return

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

Example

';
// byte-based cut
echo "mb_strcut-4:" . mb_strcut($cn_str, 0, 4) . '
';
?>
backendPHPstring-manipulationMultibytemb_strcut
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.