Spelling Check in php. Pass checking string to function and get result in from of any error.
function checkSpell($input)
{
$word=new COM("word.application") or die("Cannot create Word object");
$word->Visible=false;
$word->WindowState=2;
$word->DisplayAlerts=false;
$doc=$word->Documents->Add();
$doc->Content=$input;
$doc->CheckSpelling();
$result= $doc->SpellingErrors->Count;
if($result!=0)
{
echo "Input text contains misspelled words.\n\n";
for($i=1; $i <= $result; $i++)
{
echo "Original Word: " .$doc->SpellingErrors[$i]->Text."\n";
$list=$doc->SpellingErrors[$i]->GetSpellingSuggestions();
echo "Suggestions: ";
for($j=1; $j <= $list->Count; $j++)
{
$correct=$list->Item($j);
echo $correct->Name.",";
}
echo "\n\n";
}
}
else
{
echo "No spelling mistakes found.";
}
$word->ActiveDocument->Close(false);
$word->Quit();
$word->Release();
$word=null;
}
$str="Hellu world. There is a spellling error in this sentence.";
SpellCheck($str);
?>
No comments:
Post a Comment