Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

mb_str_split

Description

Given a multibyte string, return an array of its characters

Syntax

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

Parameters

string

The string to split into characters or chunks.

length

If specified, each element of the returned array will be composed of multiple characters instead of a single character.

encoding

The encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used.

Return

Returns an array of strings.

Examples

1 · string

<?

$string = '🐘string';

$return = mb_str_split($string);

print_r($return);

?>
Array
(
    [0] => 🐘
    [1] => s
    [2] => t
    [3] => r
    [4] => i
    [5] => n
    [6] => g
)

2 · length

<?

$string = '🐘string';
$length = 3;

$return = mb_str_split($string, $length);

print_r($return);

?>
Array
(
    [0] => 🐘st
    [1] => rin
    [2] => g
)

3 · encoding

<?

$string = '🐘string';
$length = 3;
$encoding = 'UTF-8';

$return = mb_str_split($string, $length, $encoding);

print_r($return);

?>
Array
(
    [0] => 🐘st
    [1] => rin
    [2] => g
)
HomeMenu