Php, enchant library, how to choose dictionary (like aspell or myspell)

1.3k views Asked by At

I'm trying Enchant spell library.

I have a script that works fine, But I would be able to choose between several dictionaries (Aspell or Myspell)

So as I tried this function enchant_broker_set_dict_path, but it seems to have no effects. And this function is not in the phpdoc, Why ?

Tried on linux, with php 5.3

Here is my script

$words=array('test', 'test');

$suggestions = array();
$enchant = enchant_broker_init();

if (enchant_broker_dict_exists($enchant, $lang)) {
        $dict = enchant_broker_request_dict($enchant, $lang);

        foreach ($words as $word) {
            $correct = enchant_dict_check($dict, $word);
            if (!$correct) {
                $suggs = enchant_dict_suggest($dict, $word);

                if (!is_array($suggs)) {
                    $suggs = array();
                }
                $suggestions[$word] = $suggs;
            }
        }
        enchant_broker_free_dict($dict);
        enchant_broker_free($enchant);
    } else {
        enchant_broker_free($enchant);
        throw new Exception("Could not find dictionary. Code: " . $lang);
    }
2

There are 2 answers

0
kostas On

Where exactly do you use it in your code?
There was a bug, if you called enchant_broker_get_dict_path before enchant_broker_set_dict_path it wouldn't work.
Also this could help: http://blog.iwanluijks.nl/?!=/post/1-using-enchant-with-php-on-windowspart-1.html

If you use PECL then notice that you need version 1.1.0 or higher since enchant_broker_set_dict_path and enchant_broker_get_dict_path were included in that version.
http://pecl.php.net/package/enchant/1.1.0

0
aimiliano On

Php should have enabled php_enchant extention in order to use those functions.

Use your php.ini to setup the php to enable this extention.

if you are on windows, then add extension=php_enchant.dll to your php.ini file.

Also the documentation or the enchant commands are at http://www.php.net/manual/en/function.enchant-broker-init.php