Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中检查拼写并建议正确的单词_Php_Spell Checking - Fatal编程技术网

在PHP中检查拼写并建议正确的单词

在PHP中检查拼写并建议正确的单词,php,spell-checking,Php,Spell Checking,我想知道是否有人知道任何库、脚本或服务可以拼写检查字符串并返回正确拼写单词的建议,或者如果有多个正确拼写的单词可以用PHP编写,则返回建议 如果我能做的查询数量没有限制的话,我会更喜欢,所以我不喜欢谷歌的API 如果它能像这样工作,那就太好了: // string to be spell checked stored in variable $misspelledString = "The quick brown lama jumped over the lazy dog."; //pass

我想知道是否有人知道任何库、脚本或服务可以拼写检查字符串并返回正确拼写单词的建议,或者如果有多个正确拼写的单词可以用PHP编写,则返回建议

如果我能做的查询数量没有限制的话,我会更喜欢,所以我不喜欢谷歌的API

如果它能像这样工作,那就太好了:

// string to be spell checked stored in variable
$misspelledString = "The quick brown lama jumped over the lazy dog.";

//pass that variable to function

//function returns suggestion or suggestions as an array of string or strings

$suggestion = spellCheck($misspelledString);

echo "Did you mean ".$suggestion[0];

您可以尝试包括的Pspell功能:

或者一个外部插件,比如:


查看一个例子。

不是像您的例子中那样好的API,但是Pspell将是一个选项。它可能已经包含在PHP的系统副本中。要检查的每种语言都需要aspell库。


在我的基于debian的机器上,它作为一个单独的包php5 pspell包含在系统存储库中。

我试图创建一个类,该类获取短语列表并将其与用户输入进行比较。我想做的是让Porshre Ceyman这样的东西改成保时捷Cayman

此类需要一个包含正确术语的数组$This->full\u model\u列表,以及一个包含用户输入的数组$search\u terms。我拿到了施工图,所以你需要通过完整的模型列表。请注意,这并没有完全起作用,所以我决定放弃它,它是根据一个想纠正大句的人改编的

你可以这样称呼它:

$sth = new SearchTermHelper;
$resArr = $sth->spellCheckModelKeywords($search_terms)
代码(非常测试版):

您需要有“pspell”PHP扩展,您可以使用CLI在Linux上安装它:

sudo apt-get install php-pspell;
sudo service apache2 restart;
代码非常简单:

if ($word = $_GET['word']) {
    $spellLink = pspell_new("en");

    if (!pspell_check($spellLink, $word)) {
        $suggestions = pspell_suggest($spellLink, $word);
        echo '<p>Did you mean: <i>"'.$suggestions[0].'"</i>?</p>';
    }
}
if($word=$\u GET['word'])){
$spellLink=pspell_new(“en”);
如果(!pspell_check($spellLink,$word)){
$suggestions=pspell\u suggestion($spellLink,$word);
echo'您的意思是:“.$suggestions[0]”?

; } }
我的机器上有PHP 5.3,手册上说PSpell不再是PHP的一部分。你能在你的服务器上安装软件包吗?它是托管的吗,我认为我不允许安装任何软件包。我的服务器上有PHP5.3,PSpell不是该版本或以后版本的一部分。@Filippos有没有从输入中获取输入、检查拼写以及在没有模式或弹出窗口的搜索结果页上显示更正建议的示例?
if ($word = $_GET['word']) {
    $spellLink = pspell_new("en");

    if (!pspell_check($spellLink, $word)) {
        $suggestions = pspell_suggest($spellLink, $word);
        echo '<p>Did you mean: <i>"'.$suggestions[0].'"</i>?</p>';
    }
}