Creating a Spell Checker with PHP
Submitted by charlie.collins on Sun, 02/10/2002 - 22:08
Tagged:
I recently undertook the task of implementing a spell checking solution using PHP. The solution was intended to be used on a website that allows users to submit content.
I had a few specific goals for the spell checker in mind before I started. The solution needed to be able to allow users to spell check HTML form submitted content by showing users potentially misspelled words, allowing users to click on "suggested" replacement words and allowing users to add words to a custom dictionary. The solution also needed to be PHP based and NOT use client side stuff such as JavaScript (it has to work always, not just on particular browsers and not just when certain features of a browser are enabled).
I was all set for a major endeavor and was pleasantly surprised that with PHP this is relatively easy.
First off you have to a spell checking library. The aspell/pspell package available for just about any UNIX platform fits this bill. Secondly, PHP has to have aspell/pspell support compiled in. Lastly, you gotta write some PHP to use the aspell/pspell stuff via the pspell PHP functions.
Here is the more specific breakdown:
- 1. Get aspell/pspell (see related links) and configure/make/make install (all default, nothing special required). Note- I had some issues with the RPMs on Red Hat 7.x for aspell/pspell and the locations of libraries, I had to remove the RPMs and use the default compile-installs and then all worked fine.
- 2. Configure PHP with aspell/pspell support. I already had PHP, but did not have these packages compiled in. aspell is the actual spell checking engine, and pspell is the interface to it. After looking at the PHP docs I noticed that most of the aspell functions are deprecated and so decided that I would try with just pspell. It worked fine. recompile PHP (see the php.net documentation if you need help with that) with --enable-pspell option.
- 3. Get cracking with some PHP code to use this new stuff. For more on my implementation of this, see the next section.







Comments
Re: Creating a Spell Checker with PHP
You can even do it .NET