使用Microsoft Word的拼写/语法检查与PHP

时间:2014-12-17 07:54:07

标签: php spell-checking

我从1天开始搜索是否有任何方法可以使用来自php的Microsoft拼写检查和语法检查。我试图使用dotnet类和Microsoft.Office.Interop.Word但未能使用单词拼写检查。有什么建议..?

1 个答案:

答案 0 :(得分:-1)

我无法测试这个,但这是在PHP COM Functions页面上发布的一个示例,你试过这个吗?

<?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);
?>

来源:PHP: COM Functions