我正在尝试让 PHP 拼写检查应用程序正常工作,但是当我尝试使用 Enchant 扩展时,我无法让它检查单词的拼写错误。
网络服务器配置
- PHP 版本 5.4.7
- 视窗服务器 2008
- IIS 7
在 php.ini 文件中,我启用了 Enchant 扩展。例如:
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:
但是,这并不能告诉我“soong”这个词是否拼写正确!