首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将美国单词转换为英国对等词

将美国单词转换为英国对等词
EN

Stack Overflow用户
提问于 2017-05-23 09:35:57
回答 1查看 143关注 0票数 3

我有一个自动校正字符串的函数。它按照预期纠正拼写错误的单词。我面临的问题是,它不会将一个美国拼写的单词更正为英国的同义词。

代码语言:javascript
复制
$pspell = pspell_new('en','british','','utf-8',PSPELL_FAST);

function spellCheckWord($word) {
    global $pspell;
    $autocorrect = TRUE;

    // Take the string match from preg_replace_callback's array
    $word = $word[0];

    // Ignore ALL CAPS
    if (preg_match('/^[A-Z]*$/',$word)) return $word;

    // Return dictionary words
    if (pspell_check($pspell,$word))
        return $word;

    // Auto-correct with the first suggestion
    if ($autocorrect && $suggestions = pspell_suggest($pspell,$word))
        return current($suggestions);

    // No suggestions
    return $word;
}

function spellCheck($string) {
    return preg_replace_callback('/\b\w+\b/','spellCheckWord',$string);
}

echo spellCheck('This is a color.'); 

上面的示例没有检测到拼写错误。如何将color更改为colour,将favorite改为favourite等单词相同?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-23 10:39:37

查看pspell_new()方法的正式文档--对于“拼写”参数的不同值有一个注释,该参数用于设置使用哪种语言版本;

我认为不同的PHP版本和/或A拼写/UNIX发行版的语言和拼写参数不同。 我的PHP5.2.6 Debian忽略了拼写参数。 相反: 对于美国人来说,使用en_US作为语言。英国使用en_GB (非en_UK)加拿大使用en_CA

看起来这个值可能会根据您的服务器配置而改变。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44131047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档