Aleksej_Shherbak
Aleksej_Shherbak

Reputation: 3088

Pspell don't work

Please, help me with pspell problem. I have installed aspell and I have done following comands in terminal:

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

My os is linux Mint 17. PHP - 7.0.28. When i try to use function-checker it return me empty array. But i know definetly that it works correct in hosting. Code of function:

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);
    }
}

Upvotes: 3

Views: 525

Answers (1)

braandl
braandl

Reputation: 96

I have only tried with PHP8.1, but like this it runs smoothly on my system. Install the dependencies (e.g. for Ubuntu):

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

or Alpine:

apk add aspell aspell-en php81-pspell

then you can run in PHP:

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

Make sure to give it your phrase word by word, it can not handle sentences or unusual sequences.

Upvotes: 1

Related Questions