Ok so I hear you saying, how the hell can I use Hunspell and PHP with Windows, Now the way I am going to show you isn’t the only way but is a much simpler way without compiling and using binaries.
What is Hunspell?
Well I can re-write what’s already written, however if you wish to find out, please check the link below
Long story cut short, Hunspell is a tool that you can use to validate your text against a given dictionary, get options for correct spellings for a wrongly spelt words.
What to do next on Windows 8/10?
First thing first you have to get the executables, I’ve got hunspell-1.3.2-3-w32-bin.zip, download and extract it to say c:\Hunspell
so path to bin folder will look like c:\Hunspell\bin
This is where you will find hunspell.exe
Great so far so good, now let’s add our bin folder to our Environment PATH,
Setting Environment variable PATH
Step 1
Goto Control Panel
–> System
–> Advanced system settings
–> “Advanced
” tab –> “Environment Variables
”
Step 2
Under “System variables
” window select “Path
” and click “Edit” button
Step 3
A window “Edit System Variable” will pop up showing the current value of “Path”. At the end of that string add ;c:\Hunspell\bin
Step 4
Click Ok buttons to exit current open pop up windows
We are pretty much set, now open your command prompt and type
1 |
c:\hunspell |
You will see something like this
1 2 |
C:\Users\jas.chahal>hunspell Hunspell 1.3.2 |
Now try typing
baddd and press enter
You will see something like this
1 |
& baddd 6 0: badder, baddie, baddest, bad, bated, Bard |
Above line is just options of matching words to correct the misspelled word. This step validates that our installation works ok. However you may see error something like this
1 2 3 4 5 6 7 8 9 |
Can't open affix or dictionary files for dictionary named en_US Or Can't open affix or dictionary files for dictionary named en_AU or Can't open affix or dictionary files for dictionary named en_UK |
This means that dictionary definitions are missing, how to recover from this situation
First thing to do is to use hunspell command with -D flag
1 |
c:\hunspell -D |
This will give you list of paths where Hunspell search for dictionaries, First one for me is listed as c:\Hunspell\share\hunspell
Downloading dictionaries
You have to search for Word list for your own language, however if you are keen to know a couple of resources, you can use something like http://wordlist.aspell.net/ etc Once downloaded, copy and paster .aff and .dic file in the default search folder and you are all set.
By this time I hope that hanspell installation is working so we take this to next level.
In part 2 of this post, I will show you how you can utilize PHP to validate your text for spelling mistakes.
I will see you in next post, stay tuned.
Where is part 2?