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