$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 开始计数);