0

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?

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by ivan3510
0

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 :)

0

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 :)

Edited by twiss: n/a

0

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

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.