Add Spell Check in PHP With PSpell

pradeep's Avatar author of Add Spell Check in PHP With PSpell
This is an article on Add Spell Check in PHP With PSpell in PHP.
Rated 4.67 By 3 users
Most applications like browsers, text editors, etc. come built in with spelling suggestions, they highlight a possible incorrect English word (any language for that matter) and offers a list of suggestions when clicked or selected. Even, search engines provide spelling suggestions.

Even you might want to provide spelling corrections to your web application, with PHP and it's Pspell extension it wouldn't be very hard to implement. Pspell extension uses the Aspell library (http://aspell.sourceforge.net/). In this article we will look at installing & using the Pspell extension for spelling suggestions.

Pspell Installation



You need to have Aspell library to compile PHP with Pspell extension, add the following option with path Aspell source to configure:

Code:
--with-pspell[=dir]

For Windows users, get the ASpell for Windows from Aspell webiste, then get the dictionaries you need from (http://aspell.net/win32/), finally in the php.ini enable extension=php_pspell.dll.

Basic Usage of Pspell



I'll demonstrate a few basic examples of Pspell, try and tweak according to your requirements.

Code: PHP
<?php
// create a handle
$pspell_link = pspell_new("en");

// check the word
if (!pspell_check($pspell_link, "testt")) {
    // get suggestions from pspell
    $suggestions = pspell_suggest($pspell_link, "testt");

    // print out the suggestions
    foreach ($suggestions as $suggestion) {
        echo "Possible spelling: $suggestion<br />";
    }
}
?>

Well, that's all there needs to be known for you to enable your application to check spelling. Please give feedback and experiences to the community.
shabbir like this