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
Syntax
mb_str_split(string $string, int $length = 1, ?string $encoding = null): array
Parameters
| Parameter | Description |
|---|---|
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
<?php
print_r(mb_str_split("héllo"));
Output
Array
(
[0] => h
[1] => é
[2] => l
[3] => l
[4] => o
)<?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
| Version | Change |
|---|---|
| PHP 7.4 | Added |
Related
str_split()· Split a string into an array of chunks of a given length, one byte each by default. Use mb_str_split() for UTF-8.mb_strlen()· Return the number of characters in a string, counting é or 日 as one character. The UTF-8-safe version of strlen().strrev()· Reverse a string byte by byte. Fine for ASCII, but it breaks multibyte characters such as é.- PHP Strings · tutorial