附魔拼写检查不工作.Windows下的配置


PHP: Enchant Spell Checking not working. Configuration in Windows?

我试图得到一个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:

然而,这并没有告诉我单词"song"是否拼写正确!

事实证明,在Windows, IIS和PHP 5.4.7中获得Enchant扩展是很容易的!

所有你需要做的是创建一些文件夹,下载一些字典文件和它的工作出色!

去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 # 109925http://my.opera.com/iwanluijks/blog/using-enchant-with-php-on-windows-part-1

在我的例子中,它甚至没有列出这些后端!!

你需要复制libenchant_ispell.dll和libenchant_myspell.dll到"c:'PHP'lib'enchant"。

然后在下载字典并使用此未记录的函数后:

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

我终于成功了!

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

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

在执行了这些步骤并删除了Paul代码中对enchan_broker_set_dict_path()的调用之后,它运行得非常好。