Forum Moderators: coopster

Message Too Old, No Replies

PHP Spell Checker.

         

tonynoriega

7:32 pm on Feb 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



looking for a spell checker that will check a <textarea> for a Contact Management Application i built that ...obviously....will check the spelling before being submitted to the dbase...?

anything simple out there that i should look at implementing?

jatar_k

7:38 pm on Feb 5, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe
[php.net...]

tonynoriega

2:47 pm on Feb 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, i found a really easy ...somewhat...example..

i know i have the pspell library complied on my server, and i also have PCRE library....

I am trying to incorporate a spell checker into a textarea in one of my forms...

i found this example on the php.net site, but am unable to get it to work...

Here is my page code for the textarea:
*****************************************************
<input type="button" value="Spell Check" onClick="spellCheckWord();">
<br />
<textarea name="builder_remarks" style="width: 400px; height: 200px;" id="builder_remarks" type="text" ></textarea>
****************************************************

then the pspell function is in a file called spellcheck.php which i call via include:
*****************************************************
include ('spellcheck.php');
*****************************************************
below is spellcheck.php
*****************************************************
<?php
$pspell = pspell_new('en','canadian','','utf-8',PSPELL_FAST);

function spellCheckWord($word) {
global $pspell;
$autocorrect = TRUE;

// Take the string match from preg_replace_callback's array
$word = $word[0];

// Ignore ALL CAPS
if (preg_match('/^[A-Z]*$/',$word)) return $word;

// Return dictionary words
if (pspell_check($pspell,$word))
return $word;

// Auto-correct with the first suggestion, color green
if ($autocorrect && $suggestions = pspell_suggest($pspell,$word))
return '<span style="color:#00FF00;">'.current($suggestions).'</span>';

// No suggestions, color red
return '<span style="color:#FF0000;">'.$word.'</span>';
}

function spellCheck($string) {
return preg_replace_callback('/\b\w+\b/','spellCheckWord',$string);
}

echo spellCheck('PHP is a reflecktive proegramming langwage origenaly dezigned for prodewcing dinamic waieb pagges.');
?>