"Did you mean ... ?"

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

"Did you mean ... ?"

Post by bytte »

Hi all,

I have a website where a user can enter the name of a band. Then the name will be inserted into the MYSQL database. However, I want to avoid multiple entries as much as possible.
That's why I thought it would be good to have a page that checks for bandnames that are more or less similar. Before inserting the new bandname in the database the user would see a page " DID YOU MEAN ... ? ".

Like e.g. he would type "ACDC"
The page would display: DID YOU MEAN "AC/DC"?

I'm looking for a function, a class or a script that helps me with this.
Any suggestions?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

I recommend querying the database to find all bands and then using these functions to calculate similarity:

[php_man]similar_text[/php_man]() (choose highest percentage match)
[php_man]levenshtein[/php_man]() (choose lowest 'cost')
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

you may also find methaphone() and soundex() usefull
bytte
Forum Commoner
Posts: 75
Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium

Post by bytte »

Thanks a lot guys!
Post Reply