gpt4 book ai didi

PHP:附魔拼写检查不工作。在 Windows 中配置?

转载 作者:可可西里 更新时间:2023-11-01 14:03:39 26 4
gpt4 key购买 nike

我试图让一个 PHP 拼写检查应用程序正常工作,但是当我尝试使用 Enchant 扩展时,我无法让它检查单词是否存在拼写错误。

网络服务器配置

  • PHP 版本 5.4.7
  • window 服务器 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”这个词是否拼写正确!

最佳答案

事实证明,让 Enchant 扩展在 Windows、IIS 和 PHP 5.4.7 中工作非常容易!

您需要做的就是创建一些文件夹,下载一些字典文件,一切都非常棒!

转到 https://wiki.mozilla.org/L10n:Dictionaries并下载您要进行拼写检查的词典。

然后在您的 PHP 文件夹中创建此目录结构:[PHP]\share\myspell\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
)

致谢:

http://www.php.net/manual/en/enchant.examples.php#109925

http://my.opera.com/iwanluijks/blog/using-enchant-with-php-on-windows-part-1

关于PHP:附魔拼写检查不工作。在 Windows 中配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16728842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com