Similar text

Shows how to use the similar_text() function to compare similar words.
It returns how similar the words are.

$word2compare = "stupid";
$words = array(
    'stu and pid',
while(list($id, $str) = each($words)){
    similar_text($str, $word2compare, $percent);
    print "Comparing '$word2compare' with '$str': ";
    print round($percent) . "%\n";
Comparing 'stupid' with 'stupid': 100%
Comparing 'stupid' with 'stu and pid': 71%
Comparing 'stupid' with 'hello': 0%
Comparing 'stupid' with 'foobar': 0%
Comparing 'stupid' with 'stpid': 91%
Comparing 'stupid' with 'upid': 80%
Comparing 'stupid' with 'stuuupid': 86%
Comparing 'stupid' with 'sstuuupiiid': 71%
Snippet Details

Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!

Older comments:

rem45acp June 15, 2009 at 06:08
what if you wanted to find the simularity between all of those words? instead of comparing 'stupid' to all the others, what if you wanted to find which one out of all of the words is the most similar to the others?
Per Nielsen April 03, 2008 at 01:20
Not bad, nice one!