Im trying to implement word correction like google's Did you mean .....
I looked at here here

I tried the code:

<?php
function spellcheck ( $string ) {
   $words = split(' ',$string);
   $misspelled = $return = array();
   pspell_config_create("en",PSPELL_NORMAL);
   $int = pspell_new('en');
   foreach ($words as $value) {
       $check = preg_split('/[\W]+?/',$value);
       if (($check[1] != '') and (strpos("'",$value) > 0) ) {$check[0] = $value;}
       if (($check[0] + 1 == 1) and (!pspell_check($int, $check[0]) )) {
           $res  .= '<SPAN class="misspelled" style="color:#FF0000; font-weight:bold;">' . $value . ' </SPAN> ';
           $poss = pspell_suggest($int,$value);
           $orig = metaphone($value);
           foreach ($poss as $suggested)
           {
                 $ranked[metaphone($suggested)] = $suggested;
           }
           if ($ranked[$orig] <> '') {$poss[1] = $ranked[$orig];}

       $res2  .= '<SPAN style="color:#CC8800; font-weight:bold">' . $poss[1] . ' </SPAN> ';

   } else {
   $res .= $value . ' ';
   $res2 .= $value . ' ';
   }
   }

   $n[1] = $res;
   $n[2] = $res2;
   return $n;
}
?>

But my page displays it does not recognize methods pspell_config_create(), pspell_new() ...

How can I correct it? Did I miss something or do I have to write my own methods for those methods? It would be best if someone can post a correct and complete functions here 😉

Thanks

    you mean it says, call to undefined function pspell_new...?

    if so, this means you need to install the aspell library files from http://aspell.sourceforge.net and reconfigure php to support the library, for linux you recompile with the switch --with-pspell[=dir] or on windows copy aspell-15.dll to the system32 folder.

      would this be the place to download library
      [url]ftp://ftp.gnu.org/gnu/aspell/[/url]

      which files should I download? Please give me more detail.

      Thank you very much

        [url]ftp://ftp.gnu.org/gnu/aspell/aspell-0.60.3.tar.gz[/url]

        install that and recompile php to include the --with-pspell=/path/to/aspell

          Write a Reply...