I'm trying to mess around will spell checking via pspell. I'm just looking to make this code get some text and highlight the mispelled words. I know I can do more with it, but that's all I want right now. For some reason it thinks every word is misspelled. Eventually I'll want to highlight mispelled words and next to the word have a drop down box with all the possibilites in it.
class spell_checker {
var $personal_path = "/speller/";
var $skip_len = 3;
var $mode = PSPELL_NORMAL;
var $pspell_handle;
var $pspell_cfg_handle;
var $personal = false;
function spell_checker($dict = "en", $pconfig = "") {
$pspell_cfg_handle = pspell_config_create($dict);
pspell_config_ignore($pspell_cfg_handle,$skip_len);
pspell_config_mode($pspell_cfg_handle, $mode);
if($pconfig != "") {
$pspell_handle = pspell_config_personal($pspell_cfg_handle, $personal_path.$pconfig.".pws");
$personal = true;
}
$pspell_handle = pspell_new_config($pspell_cfg_handle);
}
function suggest($word) {
return pspell_suggest($this->pspell_handle, $word);
}
function check($word) {
return pspell_check($this->pspell_handle, $word);
}
function add($word) {
if(!$personal) return false;
return pspell_add_to_personal($this->pspell_handle, $word);
}
function close() {
if(!$personal) return;
return pspell_save_wordlist($this->pspell_handle);
}
}
function CheckSpelling($mystr) {
$spell_chk = new spell_checker("en", "");
$spell_chk->add('bunk');
$spell_chk->add('bunkology');
$spell_chk->add('bunkism');
$outstr = "";
$words = split("[^[:alpha:]']+", $mystr);
foreach($words as $val) {
if($spell_chk->check($val)) {
$outstr = $outstr . $val;
} else {
$outstr = $outstr . "<span style='background-color: #FF0000'><font color= '#000000' face='Arial' size=2>$val </font></span>";
foreach($spell_chk->suggest($val) as $suggestion) {
echo ' '.$suggestion;
}
echo "$val<br>";
}
}
$spell_chk->close();
return $outstr;
}