Answers
function str_split_unicode($str, $l = 0) {
if ($l > 0) {
$ret = array();
$len = mb_strlen($str, "UTF-8");
for ($i = 0; $i < $len; $i += $l) {
$ret[] = mb_substr($str, $i, $l, "UTF-8");
}
return $ret;
}
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
}
$s = '中华人民abc共和\x01国';
print_r(str_split_unicode($s));
Array
(
[0] => 中
[1] => 华
[2] => 人
[3] => 民
[4] => a
[5] => b
[6] => c
[7] => 共
[8] => 和
[9] => \
[10] => x
[11] => 0
[12] => 1
[13] => 国
)
邻居的耳朵
answered 10 years, 7 months ago