Примеры
Пример #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";
$spellerrors = enchant_dict_check($d, "soong");
print_r($dprovides);
echo "found $spellerrors spell errors\n";
if ($spellerrors) {
$suggs = enchant_dict_suggest($d, "soong");
echo "Suggestions for 'soong':";
print_r($suggs);
}
enchant_broker_free_dict($d);
} else {
}
enchant_broker_free($r);
?>
Коментарии
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.
To repeat a note by wschalle at gmail dot com on page book.enchant
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.
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.