Forum Moderators: coopster
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.');
?>