The mb_str_split Function
The mb_str_split function splits a string in a multibyte encoding (for example, UTF-8) into an array of characters or parts of a specified length. The first parameter is the string to split, the second is the length of each part, and the third is the encoding.
Syntax
mb_str_split(string, [length], [encoding]);
Example
Let's split a string into individual characters:
<?php
$res = mb_str_split('абвгд');
print_r($res);
?>
Code execution result:
['а', 'б', 'в', 'г', 'д']
Example
Let's split a string into parts of 2 characters each:
<?php
$res = mb_str_split('12345', 2);
print_r($res);
?>
Code execution result:
['12', '34', '5']
Example
Let's split a string with explicit specification of UTF-8 encoding:
<?php
$res = mb_str_split('日本語', 1, 'UTF-8');
print_r($res);
?>
Code execution result:
['日', '本', '語']