Add Spell Check in PHP With PSpell

Discussion in 'PHP' started by pradeep, Mar 28, 2013.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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.

    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 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice