拼写检查(Pspell)无法工作

3

请帮我解决pspell问题。我已经安装了aspell,并在终端中执行了以下命令:

sudo apt-get install libpspell-dev 
sudo apt-get install php7.0-pspell
sudo apt-get install aspell-en

我的操作系统是Linux Mint 17,PHP版本为7.0.28。当我尝试使用函数检查器时,它会返回一个空数组。但我确定它在托管环境中是正确的。函数代码:

function fixMistakeInQString($string, $lang){
    $pspell_config = pspell_config_create($lang);
    pspell_config_mode($pspell_config, PSPELL_FAST);
    $pspell_link = pspell_new_config($pspell_config);


    if (!pspell_check($pspell_link, $string)) {
        $result = pspell_suggest($pspell_link, $string);
        foreach ($result as $key => $value){
            if(preg_match('~\s~ui', $value) || preg_match('~-~ui', $value)){
                unset($result[$key]);
            }
        }
        return $result;
    }else{
        return array($string);
    }
}
1个回答

1

我只尝试过PHP8.1,但是这样做在我的系统上可以平稳运行。 安装依赖项(例如Ubuntu):

sudo apt install aspell
sudo apt install php8.1-pspell
sudo apt install aspell-en

或者阿尔卑斯:
apk add aspell aspell-en php81-pspell

然后您可以在PHP中运行:

<?php
$pspell = \pspell_new("en", null, null, "utf-8", PSPELL_FAST);
if (!\pspell_check($pspell, $word)) {
    $suggesstion = \pspell_suggest($pspell, $word);
}

请确保逐字逐句地输入您的短语,它无法处理完整的句子或不寻常的序列。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接