HI!

I have a php page. There are music names (they are in array). I want to make a search script. This script must find what someone writes. But if user made mistake while writing, it must find similar music names. Is this possible, or I must use mysql?

Recommended Answers

All 5 Replies

Hi!
You're trying to make something like Google Suggest.
Perhaps, you will use/need functions such as similar_text(), levenshtein(), soundex() and metaphone(). You can read about these functions ofc in official php-manual.
Good Luck!

P.S.: Sorry for my bad English :)

There are two functions in PHP that return the difference of two strings. The faster and probably better one is levenshtein:

levenshtein('ab', 'abc'); // 1
levenshtein('abc', 'a'); // 2
levenshtein('abc', 'ac'); // 1

The other one is similar_text, that uses Oliver's description:

similar_text('ab', 'abc'); // 66.6667 %

Edit: oops. Should have refreshed a bit earlier :)

OK. What number would you put as maximal (diferences) (in levenshtein)?

I would make it (less than 2 or 3) or (less than 15% of the string you compare to).
Or: add all hits for $diff == 0 , and than (while you have less than 10 hits) add all hits for $diff == 1, 2, and 3.

OK. Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.