将utf8字符串拆分为字符数组 [英] Split utf8 string into array of chars
本文介绍了将utf8字符串拆分为字符数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将 utf8 编码的字符串拆分为字符数组.我现在使用的功能曾经可以使用,但是由于某种原因它不再起作用了.可能是什么原因.而且更好的是,我该如何解决?
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. What could be the reason. And better yet, how can I fix it?
这是我的字符串:
Zelf heb ik maaréénvraag:wie ben jij?
Zelf heb ik maar één vraag: wie ben jij?
这是我的功能:
function utf8Split($str, $len = 1)
{
$arr = array();
$strLen = mb_strlen($str);
for ($i = 0; $i < $strLen; $i++)
{
$arr[] = mb_substr($str, $i, $len);
}
return $arr;
}
这是结果:
Array
(
[0] => Z
[1] => e
[2] => l
[3] => f
[4] =>
[5] => h
[6] => e
[7] => b
[8] =>
[9] => i
[10] => k
[11] =>
[12] => m
[13] => a
[14] => a
[15] => r
[16] =>
[17] => e
[18] => ́
[19] => e
[20] => ́
[21] => n
[22] =>
[23] => v
[24] => r
[25] => a
[26] => a
[27] => g
[28] => :
[29] =>
[30] => w
[31] => i
[32] => e
[33] =>
[34] => b
[35] => e
[36] => n
[37] =>
[38] => j
[39] => i
[40] => j
[41] => ?
)
推荐答案
我发现é不是我期望的字符.显然,né和ńe之间是有区别的.我首先通过规范化字符串来使它工作.
I found out the é was not the character I expected. Apparently there is a difference between né and ńe. I got it working by normalizing the string first.
这篇关于将utf8字符串拆分为字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文