首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP:附魔法术检查无效。Windows中的配置?

PHP:附魔法术检查无效。Windows中的配置?
EN

Stack Overflow用户
提问于 2013-05-24 06:25:43
回答 3查看 4.4K关注 0票数 5

我试图让一个PHP拼写检查应用程序工作,但当我尝试使用附魔扩展,我无法让它检查一个单词的拼写错误。

Web服务器配置

  • PHP版本5.4.7
  • Windows 2008
  • IIS 7

在php.ini文件中,我启用了增强扩展。例:

代码语言:javascript
复制
extension=php_enchant.dll

示例代码

代码语言:javascript
复制
    $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);

返回

代码语言:javascript
复制
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:

然而,这并没有告诉我“宋”这个词的拼写是否正确!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-05-24 06:25:43

事实证明,在Windows、IIS和PHP5.4.7中使用这个增强扩展是非常容易的!

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

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

然后在PHP文件夹中创建这个目录结构:PHP\share\my拼写\dicts

最后,放置*.aff和*.dic文件(例如。en_US.aff和en_US.dic)进入dicts文件夹,然后它就能工作了!

现在,上面的代码返回字典信息,以及拼写建议!

代码语言:javascript
复制
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
)

Credits

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

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

票数 2
EN

Stack Overflow用户

发布于 2013-11-24 01:07:44

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

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

然后,在下载字典并使用这个无文档的函数之后:

代码语言:javascript
复制
enchant_broker_set_dict_path($broker, ENCHANT_MYSPELL, 'C:\PHP\enchant\MySpell');

我终于成功了!

票数 2
EN

Stack Overflow用户

发布于 2015-03-17 15:35:30

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

  1. 取消extension=php_enchant.dll行在php.ini中的注释
  2. 将php安装目录添加到windows路径。否则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/my拼写/dicts中。您也必须创建这些文件夹。这些文件可以在C:\Program \Firefox\字典中找到,名称略有不同。但是,它们必须重命名为en_US.aff和en_US.dic,否则就无法工作。

在完成这些步骤并移除保罗代码中对enchant_broker_set_dict_path()的调用之后,它工作得很好。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16728842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档