使用Microsoft Word';使用php进行拼写/语法检查

使用Microsoft Word';使用php进行拼写/语法检查,php,spell-checking,Php,Spell Checking,我从1天开始搜索,以查找是否有任何方法可以从php使用Microsoft拼写检查和语法检查。我试图使用dotnet类和Microsoft.Office.Interop.Word,但未能使用单词拼写检查器。有什么建议吗?我无法测试,但这是PHP COM函数页面上发布的一个示例,您尝试过吗 <?php function SpellCheck($input) { $word=new COM("word.application") or die("Cannot create Word ob

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

我无法测试,但这是PHP COM函数页面上发布的一个示例,您尝试过吗

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


来源:

谢谢James Hunt,但当我试图运行代码时,我被错误“未捕获异常”com_exception“击中,消息为“未能创建com对象”“word.application”“系统是否安装了word com对象?”当我尝试使用word.application的com来显示版本时,它工作正常,但是当我尝试使用上述代码时,页面不断加载,没有显示任何错误或结果。得到了解决方案。当我在ms office 2010中尝试时,它在ms office 2007中不起作用。它工作正常。谢谢JamesNo problem,如果这个答案是正确的,介意为其他用户单击“是”吗?万一这个问题发生在别人身上。