Spell check and suggest proper word in PHP

16,931

Solution 1

You can try the included Pspell functions:

http://php.net/manual/en/ref.pspell.php

Or an external plugin, like this one:

http://www.phpspellcheck.com/

Check this SO question for an example.

Solution 2

You need to have "pspell" PHP extension, you can install it on Linux using CLI:

sudo apt-get install php-pspell;
sudo service apache2 restart;

The code is very simple:

if ($word = $_GET['word']) {
    $spellLink = pspell_new("en");

    if (!pspell_check($spellLink, $word)) {
        $suggestions = pspell_suggest($spellLink, $word);
        echo '<p>Did you mean: <i>"'.$suggestions[0].'"</i>?</p>';
    }
}

Solution 3

Not quite as nice an API as in your example, but Pspell would be an option. It may already be included with your system copy of PHP. You'll need aspell libraries for each language you want to check. http://php.net/manual/en/book.pspell.php

On my debian based machine, it's included in the system repositories as a separate package, php5-pspell.

Share:
16,931
irfan mir
Author by

irfan mir

Updated on June 13, 2022

Comments

  • irfan mir
    irfan mir almost 2 years

    I was wondering if anyone knows of any library, script, or service that can spell check a string and return a suggestion of the properly spelled word or suggestions if more that one properly spelled word that it could be written in PHP.

    I would prefer if there wasn't a limit on the amount of queries I could do, so not like Google's APIs.

    It would be great if it could function like this:

    // string to be spell checked stored in variable
    $misspelledString = "The quick brown lama jumped over the lazy dog.";
    
    //pass that variable to function
    
    //function returns suggestion or suggestions as an array of string or strings
    
    $suggestion = spellCheck($misspelledString);
    
    echo "Did you mean ".$suggestion[0];
    
  • irfan mir
    irfan mir almost 11 years
    I have PHP 5.3 on my machine and the manual says PSpell is no longer part of PHP.
  • irfan mir
    irfan mir almost 11 years
    I have PHP 5.3 on my server and PSpell is not a part of that release or any after.
  • Blutack
    Blutack almost 11 years
    Are you able to install packages on your server or is it hosted?
  • irfan mir
    irfan mir almost 11 years
    It is hosted, I don't think I am allowed to install any packages.
  • VijayRana
    VijayRana about 3 years
    @Filippos is there any example for getting input from input, checking the spelling, and displaying corrected suggestions on a search result page without a modal or popup window?