我对这段代码有困难。它应该做的是取一个字符串,用单词把它分开,然后用字典检查它。然而,当字符串中包含"Umlaut“itüit时,它会在那里被分割。
我很确定问题是[A-ZäöüÄÖÜ\'],似乎我把特殊的字符包括错了,但是怎么会呢?
$string = "Rechtschreibprüfung";
preg_match_all("/[A-ZäöüÄÖÜ\']{1,16}/i", $string, $words);
for ($i = 0; $i < count($words[0]); ++$i) {
if (!pspell_check($pspell_link, $words[0][$i])) {
$array[] = $words[0][$i];
}
}结果:
$array[0] = Rechtschreibprü"
$array[1] = "fung"发布于 2016-06-07 08:46:45
要匹配一块Unicode字母,可以使用
'/\p{L}+/u'\p{L}匹配任何Unicode字母,+匹配前面子模式的一个或多个出现,/u修饰符将模式和字符串视为Unicode字符串。
若要匹配整个单词,请使用单词边界:
'/\b\p{L}+\b/u'如果你有解说词,也可以添加\p{M}
'/\b[\p{M}\p{L}]+\b/u'https://stackoverflow.com/questions/37673990
复制相似问题