Last active
July 21, 2018 13:32
-
-
Save artemsites/19f511e17b8253206b01c55cf433d5cc to your computer and use it in GitHub Desktop.
Перевод строки в посимвольный массив с поддержкой UTF-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$string = "ЧелоБрейк"; | |
function string_split_unicode($string, $length = 1) { | |
$tmp = preg_split('~~u', $string, -1, PREG_SPLIT_NO_EMPTY); | |
if ($length > 1) { | |
$chunks = array_chunk($tmp, $length); | |
foreach ($chunks as $i => $chunk) { | |
$chunks[$i] = join('', (array) $chunk); | |
} | |
$tmp = $chunks; | |
} | |
return $tmp; | |
} | |
print_r(string_split_unicode($string, 1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment