【问题标题】:PHP: Enchant Spell Checking not working. Configuration in Windows?PHP:附魔拼写检查不起作用。 Windows 中的配置?
【发布时间】:2013-05-24 06:25:43
【问题描述】:

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

网络服务器配置

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

【问题讨论】:

  • 你是如何让 php_enchant.dll 在 Windows 上工作的。当取消注释 php.ini 中的扩展名时,php 错误日志显示“无法加载动态库 'C:\xampp\php\ext\php_enchant.dll',即使 dll 存在。它必须缺少另一个依赖项?依赖项沃克说它缺少 libenchant.dll
  • 它在我的 php 文件夹中,但该文件夹不是 windows 系统路径的一部分。

标签: php


【解决方案1】:

事实证明,让 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

【讨论】:

  • mozilla 页面上的英语词典下载链接已损坏。但我能够从 firefox 安装目录中获取它们。棘手的部分是我不得不将它们从 en-US 重命名为 en_US。
【解决方案2】:

就我而言,它甚至没有列出那些后端!!!

您需要将 libenchant_ispell.dll 和 libenchant_myspell.dll 复制到“c:\PHP\lib\enchant”。

然后在下载字典并使用这个 UNDOCUMENTED 函数之后:

enchant_broker_set_dict_path($broker, ENCHANT_MYSPELL, 'C:\PHP\enchant\MySpell');

我终于成功了!

【讨论】:

    【解决方案3】:

    我必须执行其他人在这里和其他地方建议的步骤组合。我在网上找不到一个地方将所有这些步骤都记录在同一个地方,所以我把它们写在这里。我正在使用从 xamp 安装的 Windows 7 和 php 5.5。这是我必须做的:

    1. 取消注释 php.ini 中的 extension=php_enchant.dll 行
    2. 将php安装目录添加到windows PATH。否则 php_enchant.dll 将无法找到 libenchant.dll
    3. 将 libenchant_ispell.dll 和 libenchant_myspell.dll 从 php 安装目录移至 [php]/lib/enchant/ 。您必须创建这些文件夹。
    4. 将 en_US.aff 和 en_US.dic 添加到 [php]/share/myspell/dicts 。您还必须创建这些文件夹。这些文件可以在 C:\Program Files\Firefox\dictionaries 中以稍微不同的名称找到。但必须将它们重命名为 en_US.aff 和 en_US.dic,否则它们将不起作用。

    在执行步骤并删除 Paul 代码中对 enchant_broker_set_dict_path() 的调用之后,效果很好。

    【讨论】:

    • 第 3 步解决了我在 Windows 10 上使用 wamp 的问题。在 Ubuntu 上我没有任何类似问题。
    • 该死的。为什么他们不能将其作为内置功能?所有这些复杂的步骤,如果我们错过了一个步骤,整个事情将无法正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 2011-07-18
    相关资源
    最近更新 更多