在PHP中,将字符串拆分成Unicode字符数组的最佳方式是什么?如果输入不一定是UTF-8?
我想知道输入字符串中的Unicode字符集是否是另一个Unicode字符集的子集。
为什么不直接运行mb_系列函数,就像前两个答案没有做的那样?
发布于 2009-09-09 01:23:09
我能够使用mb_*编写一个解决方案,包括一次UTF-16来回之旅,这可能是一次愚蠢的尝试,目的是加快字符串索引速度:
$japanese2 = mb_convert_encoding($japanese, "UTF-16", "UTF-8");
$length = mb_strlen($japanese2, "UTF-16");
for($i=0; $i<$length; $i++) {
    $char = mb_substr($japanese2, $i, 1, "UTF-16");
    $utf8 = mb_convert_encoding($char, "UTF-8", "UTF-16");
    print $utf8 . "\n";
}我最好避免使用mb_internal_encoding,而只是在每次mb_*调用时指定所有内容。我确信我最终会使用preg解决方案。
https://stackoverflow.com/questions/1396434
复制相似问题