php教程

范例

Example #1 Enchant Usage Example

<?php
$tag 
'en_US';
$r enchant_broker_init();
$bprovides enchant_broker_describe($r);
echo 
"Current broker provides the following backend(s):\n";
print_r($bprovides);

$dicts enchant_broker_list_dicts($r);
print_r($dicts);
if (
enchant_broker_dict_exists($r,$tag)) {
    
$d enchant_broker_request_dict($r$tag);
    
$dprovides enchant_dict_describe($d);
    echo 
"dictionary $tag provides:\n";
    
$wordcorrect enchant_dict_check($d"soong");
    
print_r($dprovides);
    if (!
$wordcorrect) {
        
$suggs enchant_dict_suggest($d"soong");
        echo 
"Suggestions for 'soong':";
        
print_r($suggs);
    }
    
enchant_broker_free_dict($d);
} else {
}
enchant_broker_free($r);
?>

User Contributed Notes

ch1902 15-Aug-2013 09:58
One thing to add to robert.johnson's very helpful post, I found that the dictionary files (*.dic and *.aff) could only contain A-Z and _ characters or they wouldn't be listed in the output of enchant_broker_list_dicts() (at least for PHP 5.4 / Windows).

This was an issue when downloading some of the dictionary files from https://addons.mozilla.org/firefox/language-tools/ where the file names contained hyphens, pt-BR for example. Just replace the hyphen with an underscore in the file name and enchant recognises the language code.
robert dot johnson at icap dot com 14-Aug-2013 04:21
To repeat a note by  wschalle at gmail dot com on page http://www.php.net/manual/en/book.enchant.php

The enchant library does not work unless libenchant_myspell.dll and libenchant_ispell.dll are placed in [PHP]\lib\enchant from PHP 5.4.13.

Dictionaries will still load from [PHP]\share\myspell\dicts.
robert dot johnson at icap dot com 03-Sep-2012 12:49
Here is help for Windows users:

You need to add dictionaries to your computer for Enchant.

1. Enchant looks in your registry keys, I don't know what keys it wants, but it looks here - I ignored all of these:
  * Default User\Software\Enchant\Config
  * Default User\Software\Enchant\Ispell
  * Default User\Software\Enchant\Myspell
2. It looks for OpenOffice dictionaries (from the registry settings for OpenOffice)
3. It looks in folder [PHP]\share\myspell\dicts

I got it working by copying the en-us dictionary files from Firefox into \share\myspell\dicts, and renaming them en_US.*.  You can download and install dictionaries from OpenOffice from here I think: http://extensions.services.openoffice.org/dictionary

Enchant creates and writes to the following folder, so you must allow PHP read and write permissions to: [SYSTEM32]\config\systemprofile\Application Data\enchant

It would be convenient if Enchant could accept parameters to specify the location of the main dictionaries and user-dictionaries, I suppose the registry keys are the only way to do it.

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788