PHP: Spell checker does not work. Windows configuration?

I am trying to run the PHP spell checker application, however, when I try to use the Enchant extension, I cannot get it to check the word for spelling errors.

Web server configuration

  • PHP Version 5.4.7
  • Windows Server 2008
  • IIS 7

In the php.ini file, I turned on the Enchant extension. eg:

extension=php_enchant.dll 

Code example :

  $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); 

Returns

 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: 

However, this does not tell me whether the word "soong" is spelled correctly or not!

+4
source share
3 answers

It turns out it's pretty easy to get the Enchant extension running on Windows, IIS and PHP 5.4.7!

All you have to do is create several folders, upload some dictionary files and work brilliantly!

Go to https://wiki.mozilla.org/L10n:Dictionaries and download the dictionaries that you want to check for verification.

Then create this directory structure in your PHP folder: [PHP] \ share \ myspell \ dicts

Finally, put the * .aff and * .dic files (for example, en_US.aff and en_US.dic) in the dicts folder, and then it will work!

Now the code above returns dictionary information, as well as spelling suggestions!

 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 ) 

Loans :

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
source

In my case, he didn’t even list those backends !!!

You need to copy libenchant_ispell.dll and libenchant_myspell.dll to "c: \ PHP \ lib \ enchant".

Then after loading the dictionaries and using this UNDOCUMENTED function:

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

I did it finally work!

+2
source

I had to follow a combination of steps suggested by others here and elsewhere. I could not find a single place on the network where all these steps were documented in the same place, so I write them here. I am using Windows 7 and php 5.5 installed from xamp. Here is what I had to do:

  • Uncomment extension = php_enchant.dll in php.ini
  • Add the php installation directory to the PATH window. Otherwise, php_enchant.dll cannot find libenchant.dll
  • Move libenchant_ispell.dll and libenchant_myspell.dll from the php installation directory to [php] / lib / enchant /. You will need to create these folders.
  • Add en_US.aff and en_US.dic to [php] / share / myspell / dicts. You will also have to create these folders. These files can be found in the C: \ Program Files \ Firefox \ dictionaries under a few names. But they must be renamed to en_US.aff and en_US.dic or they will not work.

After the steps and removing the call to enchant_broker_set_dict_path () in the Paul code, it works fine.

+2
source

Source: https://habr.com/ru/post/1482506/


All Articles