Voting

: nine plus zero?
(Example: nine)

The Note You're Voting On

naveed at php dot net
18 years ago
Here is a spell check implementation that displays the suggestion list for each misspelled word.

<?php
function SpellCheck($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);
?>

<< Back to user notes page

To Top