3

Explaining it further

Assume i have two strings like below

I am a super boy who can Fly! Really .

I am super boy who can Break walls! Really .

So some characters are similar I am super boy who can and Really . . Is there anything ready to use to find percentage similarity/diffrence between those two strings.

Anax
  • 9,122
  • 5
  • 34
  • 68
Arshdeep
  • 4,281
  • 7
  • 31
  • 46
  • This depends on how do you define similarity... – Artefacto Jul 13 '10 at 13:09
  • I am very curious to see your implementation. – Gertjan Jul 13 '10 at 13:26
  • 1
    @Gertjan apologies , read late .PHP has inbuilt functions for these comparisons . One awesome theory/algo by Levenshtein http://php.net/manual/en/function.levenshtein.php , and second with percentage results http://www.php.net/manual/en/function.similar-text.php . * I LOVE PHP * :P – Arshdeep Jul 13 '10 at 16:58

2 Answers2

5

You should look into Levenshtein Distance.

http://en.wikipedia.org/wiki/Levenshtein_distance

viggity
  • 15,039
  • 7
  • 88
  • 96
0

This SO answer to a similar question gives the PHP code for the Levenshtein, Jaro Winkler and Smith Waterman Gotoh algorithms.

I've found that Levenshtein and Jaro Winkler generally give good results for spelling mistakes between smaller strings. While the Smith Waterman Gotoh is good at comparing sentences like the example in your question.

Community
  • 1
  • 1
joshweir
  • 5,427
  • 3
  • 39
  • 59