I\'m trying to split a utf8 encoded string into an array of chars. The function that I now use used to work, but for some reason it doesn\'t work anymore. W
If you not sure about availability of mb_string function library, then use:
Version 1:
function utf8_str_split($str='',$len=1){
preg_match_all("/./u", $str, $arr);
$arr = array_chunk($arr[0], $len);
$arr = array_map('implode', $arr);
return $arr;
}
Version 2:
function utf8_str_split($str='',$len=1){
return preg_split('/(?<=\G.{'.$len.'})/u', $str,-1,PREG_SPLIT_NO_EMPTY);
}
Both functions tested in PHP5