PHP 8 reference · Multibyte String Functions

PHP mb_str_split() Function

Split a multibyte string into an array of characters, or of chunks of n characters. The UTF-8-safe str_split().

PHP 8 Since 7.4

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

mb_str_split(string $string, int $length = 1, ?string $encoding = null): array

Parameters

ParameterDescription
string The input string.
length optional Characters per chunk. Default: 1
encoding optional The character encoding; defaults to mb_internal_encoding() (UTF-8).

Return value

An array of strings.

Examples

Split into charactersTry it yourself
<?php
print_r(mb_str_split("héllo"));

Output

Array
(
    [0] => h
    [1] => é
    [2] => l
    [3] => l
    [4] => o
)
Reverse safely, chunk by charactersTry it yourself
<?php
echo implode("", array_reverse(mb_str_split("añejo"))), "\n";
print_r(mb_str_split("東京大阪京都", 2));

Output

ojeña
Array
(
    [0] => 東京
    [1] => 大阪
    [2] => 京都
)

Version history

VersionChange
PHP 7.4Added

Was this page helpful?