Fixing Common Spelling Errors

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Fixing Common Spelling Errors

Post by volomike »

I want to have a regex that fixes some common spelling errors on most of the noise words (see MySQL's noise word list as an example) and a few words on a short list I'll have for my project, like "company", which could be misspelled as cpmany or compayn.

The way it would work is to look for:

- punctuation or space
(- lowercase version of word only)
- punctuation or space

And then replace the item in parentheses above. There would be no prompting like, "Are you sure?" or identifying what we found. It would just fix them. Of course, this doesn't work with all kinds of spelling errors, but only certain spelling errors. And certain fields would be exempted such as Company Name because they might naturally have funky spellings (like Flickr for instance).

Any ideas on the best approach?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Fixing Common Spelling Errors

Post by John Cartwright »

There are many modules to handle this far better than any possible regex, including offering spelling suggestions.

http://ca.php.net/manual/tr/ref.pspell.php

Otherwise, google php spell check for an exhausting list of alternatives.
Post Reply