【发布时间】:2015-10-26 12:31:36
【问题描述】:
我从 1 天开始搜索是否有任何方法可以使用 php 中的 Microsoft 拼写检查和语法检查。我尝试使用 dotnet 类和 Microsoft.Office.Interop.Word 但未能使用单词拼写检查器。有什么建议吗?
【问题讨论】:
标签: php spell-checking
我从 1 天开始搜索是否有任何方法可以使用 php 中的 Microsoft 拼写检查和语法检查。我尝试使用 dotnet 类和 Microsoft.Office.Interop.Word 但未能使用单词拼写检查器。有什么建议吗?
【问题讨论】:
标签: php spell-checking
我无法对此进行测试,但这是发布在 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);
?>
【讨论】: