johnmahugu

php - similar text

Jun 14th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1.  
  2.  
  3. $word2compare = "stupid";
  4.  
  5. $words = array(
  6.     'stupid',
  7.     'stu and pid',
  8.     'hello',
  9.     'foobar',
  10.     'stpid',
  11.     'upid',
  12.     'stuuupid',
  13.     'sstuuupiiid',
  14. );
  15.  
  16. while(list($id, $str) = each($words)){
  17.     similar_text($str, $word2compare, $percent);
  18.     print "Comparing '$word2compare' with '$str': ";
  19.     print round($percent) . "%\n";
  20. }
  21.  
  22. /*
  23. Results:
  24.  
  25. Comparing 'stupid' with 'stupid': 100%
  26. Comparing 'stupid' with 'stu and pid': 71%
  27. Comparing 'stupid' with 'hello': 0%
  28. Comparing 'stupid' with 'foobar': 0%
  29. Comparing 'stupid' with 'stpid': 91%
  30. Comparing 'stupid' with 'upid': 80%
  31. Comparing 'stupid' with 'stuuupid': 86%
  32. Comparing 'stupid' with 'sstuuupiiid': 71%
  33. */
Advertisement
Add Comment
Please, Sign In to add comment