我试图让一个PHP拼写检查应用程序工作,但当我尝试使用附魔扩展,我无法让它检查一个单词的拼写错误。
Web服务器配置
在php.ini文件中,我启用了增强扩展。例:
extension=php_enchant.dll示例代码
$broker = enchant_broker_init();
$tag = 'en_US';
$bprovides = enchant_broker_describe($broker);
echo "Current broker provides the following backend(s):\n";
print_r($bprovides);
$dicts = enchant_broker_list_dicts($broker);
echo "Current broker provides the following dictionaries:\n";
print_r($dicts);
enchant_broker_set_dict_path($broker, ENCHANT_MYSPELL, 'C:\php5.4.7\lib\enchant\MySpell');
if (enchant_broker_dict_exists($broker, $tag)) {
$dict = enchant_broker_request_dict($broker, $tag);
$word = 'soong';
$isCorrectlySpelled = enchant_dict_check($dict, $word);
if ($isCorrectlySpelled !== true) {
$suggestions = enchant_dict_suggest($dict, $word);
echo nl2br(print_r($suggestions, true));
} else {
echo 'The word is correctly spelt!';
}
}
enchant_broker_free($broker);返回
Current broker provides the following backend(s):
Array
(
[0] => Array
(
[name] => ispell
[desc] => Ispell Provider
[file] => C:\php5.4.7\libenchant_ispell.dll
)
[1] => Array
(
[name] => myspell
[desc] => Myspell Provider
[file] => C:\php5.4.7\libenchant_myspell.dll
)
)
Current broker provides the following dictionaries:然而,这并没有告诉我“宋”这个词的拼写是否正确!
发布于 2013-05-24 06:25:43
事实证明,在Windows、IIS和PHP5.4.7中使用这个增强扩展是非常容易的!
你所需要做的就是创建一些文件夹,下载一些字典文件,它的工作非常出色!
转到https://wiki.mozilla.org/L10n:Dictionaries并下载您想要拼写检查的字典。
然后在PHP文件夹中创建这个目录结构:PHP\share\my拼写\dicts
最后,放置*.aff和*.dic文件(例如。en_US.aff和en_US.dic)进入dicts文件夹,然后它就能工作了!
现在,上面的代码返回字典信息,以及拼写建议!
Current broker provides the following backend(s):
Array
(
[0] => Array
(
[name] => ispell
[desc] => Ispell Provider
[file] => C:\php5.4.7\libenchant_ispell.dll
)
[1] => Array
(
[name] => myspell
[desc] => Myspell Provider
[file] => C:\php5.4.7\libenchant_myspell.dll
)
)
Current broker provides the following dictionaries:
Array
(
[0] => Array
(
[lang_tag] => en_GB
[provider_name] => myspell
[provider_desc] => Myspell Provider
[provider_file] => C:\php5.4.7\libenchant_myspell.dll
)
[1] => Array
(
[lang_tag] => en_US
[provider_name] => myspell
[provider_desc] => Myspell Provider
[provider_file] => C:\php5.4.7\libenchant_myspell.dll
)
)
Array
(
[0] => suing
[1] => sung
[2] => goons
[3] => song
[4] => soon
[5] => soon g
)Credits:
http://www.php.net/manual/en/enchant.examples.php#109925
http://my.opera.com/iwanluijks/blog/using-enchant-with-php-on-windows-part-1
发布于 2013-11-24 01:07:44
在我的例子中,它甚至没有列出那些后端!
您需要将libenchant_ispell.dll和libenchant_myspell.dll复制到“c:\PHP\lib\libenchant_myspell.dll”。
然后,在下载字典并使用这个无文档的函数之后:
enchant_broker_set_dict_path($broker, ENCHANT_MYSPELL, 'C:\PHP\enchant\MySpell');我终于成功了!
发布于 2015-03-17 15:35:30
我不得不执行其他人在这里和其他地方建议的步骤。我在网上找不到所有这些步骤都记录在同一个地方的地方,所以我在这里写它们。我使用从xamp安装的Windows 7和php5.5。以下是我必须做的事:
在完成这些步骤并移除保罗代码中对enchant_broker_set_dict_path()的调用之后,它工作得很好。
https://stackoverflow.com/questions/16728842
复制相似问题