$str1 = 'בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת הָאָֽרֶץ׃';
$str2 = 'בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ';
$len1 = mb_strlen($str1, 'utf-8');
for($i = 0, $arr1 = array(); $i < $len1; $i++) {
$char = mb_substr($str1, $i, 1, 'utf-8');
if (preg_match('/[\x{0591}-\x{05c7}]/u', $char)) {
end($arr1);
$key = key($arr1);
$arr1[$key] = $arr1[$key] . $char;
} else if (preg_match('/\p{Zs}/u', $char)) {
continue;
} else {
$arr1[$i] = $char;
}
}
ksort($arr1);
$arr1 = array_values($arr1);
$len2 = mb_strlen($str2, 'utf-8');
for($i = 0, $arr2 = array(); $i < $len2; $i++) {
$char = mb_substr($str2, $i, 1, 'utf-8');
if (preg_match('/[\x{0591}-\x{05c7}]/u', $char)) {
end($arr2);
$key = key($arr2);
$arr2[$key] = $arr2[$key] . $char;
} else if (preg_match('/\p{Zs}/u', $char)) {
continue;
} else {
$arr2[$i] = $char;
}
}
ksort($arr2);
$arr2 = array_values($arr2);
$results = array();
foreach ($arr1 as $key => $value) {
if ($value != $arr2[$key]) {
$results[$key] = $value;
}
}
我知道了,其結果示出
array (size=8)
3 => string 'שִׁ֖' (length=8)
7 => string 'רָ֣' (length=6)
11 => string 'הִ֑' (length=6)
14 => string 'אֵ֥' (length=6)
18 => string 'מַ֖' (length=6)
22 => string 'אֵ֥' (length=6)
25 => string 'אָֽ' (length=6)
27 => string 'ץ׃' (length=4)
3,7,11,14,18,22,25,27日字符是不同的(由右至左計數,並且從0);
來源
2013-10-23 13:58:34
nut
嘛 - 是不是那麼只是比較字符串和突出的區別? 我不認爲我會得到什麼,你實際上是在要求? –
@ AllanS.Hansen的問題是我如何提取的字符基礎上UTF-8字符的差異。 – McGafter