?
Solved

String comparison to give suggestions for misspelled words?

Posted on 2006-07-13
3
Medium Priority
?
605 Views
Last Modified: 2009-12-16
Hi,
I've got a form where someone can enter in a name of something. When submitted the name searched in the database and if found it returns the data for that name. What I want is to give a suggestion when a name is entered that is not in my database. Sort of like what Dictionary.com and Google do when you search for a misspelled word?

Anyone know how to do this?
0
Comment
Question by:Darksbane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:JB04
ID: 17103871
You can use an SQL query to find similar words like so:-


            $sql = "
            SELECT
                  *
            FROM
                  sometable
            WHERE
                  name LIKE ('%something%')
            ";


PHP also has some functions to show similar sounding words which can be used for things like this, check out the following functions:-

http://php.net/soundex
http://php.net/metaphone


0
 
LVL 35

Assisted Solution

by:Raynard7
Raynard7 earned 400 total points
ID: 17103935
You can also use the mysql soundex function;
soundex is an algorithm that goes through the letters and tries to group on similar sounds from the patterns of the words.

You could do

select * from tablename where left(soundex(name), 4) like concat(left(soundex('EnteredValue'), 4), '%')

Which would give you everything that is like the first couple of letters in the name.
0
 
LVL 1

Accepted Solution

by:
cholin earned 600 total points
ID: 17104067
Well, if you want sorta what Google does, there's a library for PHP called pSpell (www.php.net/pspell) which allows you to set specific dictionaries based on the aSpell engine.  If you make a custom dictionary that is basically all the usernames from your database, you can use the pSpell functions to suggest the closest matches with minimal code.

So basically every time a user signs up for your site, just add their username to the dictionary, and then whenever people search for a username, you can check for a match, or if there isnt one, you can suggest the closest matches.
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question