Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将美语单词转换成英语等效词_Php_Pspell - Fatal编程技术网

Php 将美语单词转换成英语等效词

Php 将美语单词转换成英语等效词,php,pspell,Php,Pspell,我有一个自动更正字符串的函数。它按预期纠正拼写错误的单词。我面临的问题是,它不会将一个美国拼写的单词改成英国对应的单词 $pspell = pspell_new('en','british','','utf-8',PSPELL_FAST); function spellCheckWord($word) { global $pspell; $autocorrect = TRUE; // Take the string match from preg_replace_ca

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

$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.'); 

上面的示例未检测到拼写错误。我如何才能让它将
颜色
更改为
颜色
,并将
收藏夹
等词更改为
收藏夹

查看该方法的官方文档-有一条关于“拼写”参数不同值的注释-用于设置使用哪种语言版本

我认为不同的PHP版本和/或aspell/UNIX发行版的语言和拼写参数不同

我的PHP5.2.6 Debian忽略了拼写参数

相反:

对美国人来说,英语是一种语言。 英国使用英国标准(非英国标准) 供加拿大使用


看起来此值可能会根据您的服务器配置而更改。

在上有一条有趣的评论,涉及使用
british
en_-GB
en_-UK
。“也许值得尝试一下。”蓝狐非常感谢。这帮助我解决了这个问题。如果你把这个作为一个答案,我会把它标记为帮助他人的正确答案。