Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/articles/php-tutorials/)
-   -   Add Spell Check in PHP With PSpell (http://www.go4expert.com/articles/add-spell-check-php-pspell-t29577/)

pradeep 28Mar2013 19:38

Add Spell Check in PHP With PSpell
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:



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

// 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.

All times are GMT +5.5. The time now is 00:45.