繁体   English   中英

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

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

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

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:

但是,这并没有告诉我“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

在我的情况下它甚至没有列出这些后端!

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

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

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

我终于成功了!

我不得不在这里和其他地方执行其他人建议的组合步骤。 我在网上找不到一个地方,所有这些步骤都记录在同一个地方,所以我在这里写。 我正在使用从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()的调用之后,它运行得很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM