Skip to content

Instantly share code, notes, and snippets.

@artemsites
Last active July 21, 2018 13:32
Show Gist options
  • Save artemsites/19f511e17b8253206b01c55cf433d5cc to your computer and use it in GitHub Desktop.
Save artemsites/19f511e17b8253206b01c55cf433d5cc to your computer and use it in GitHub Desktop.
 Перевод строки в посимвольный массив с поддержкой UTF-8
$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