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

时间:2013-05-24 06:25:44

标签: php

我正在尝试使用PHP拼写检查应用程序,但是当我尝试使用附魔扩展程序时,我无法检查单词是否存在拼写错误。

Web服务器配置

  • 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:

然而,这并没有告诉我“#34; soong"拼写是否拼写正确!

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:2)

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

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

然后在下载词典并使用此UNDOCUMENTED函数后:

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

我终于成功了!

答案 2 :(得分:2)

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

  1. 取消注释php.ini
  2. 中的extension = php_enchant.dll行
  3. 将php安装目录添加到Windows PATH。否则php_enchant.dll将无法找到libenchant.dll
  4. 将libenchant_ispell.dll和libenchant_myspell.dll从php安装目录移至[php] / lib / enchant /。您必须创建这些文件夹。
  5. 将en_US.aff和en_US.dic添加到[php] / share / myspell / dicts。您还必须创建这些文件夹。这些文件可以在C:\ Program Files \ Firefox \ dictionaries中找到,名称略有不同。但是它们必须重命名为en_US.aff和en_US.dic,否则它们将无效。
  6. 在Paul的代码中删除了对enchant_broker_set_dict_path()的调用之后,它运行得很好。