首页  >  文章  >  后端开发  >  通过php的 similar_text函数比较两个字符串的相似性

通过php的 similar_text函数比较两个字符串的相似性

WBOY
WBOY原创
2016-07-25 08:45:281044浏览
通过php的 similar_text函数比较两个字符串的相似性
  1. $word2compare = "stupid";
  2. $words = array(
  3. 'stupid',
  4. 'stu and pid',
  5. 'hello',
  6. 'foobar',
  7. 'stpid',
  8. 'upid',
  9. 'stuuupid',
  10. 'sstuuupiiid',
  11. );
  12. while(list($id, $str) = each($words)){
  13. similar_text($str, $word2compare, $percent);
  14. print "Comparing '$word2compare' with '$str': ";
  15. print round($percent) . "%\n";
  16. }
  17. /*
  18. Results:
  19. Comparing 'stupid' with 'stupid': 100%
  20. Comparing 'stupid' with 'stu and pid': 71%
  21. Comparing 'stupid' with 'hello': 0%
  22. Comparing 'stupid' with 'foobar': 0%
  23. Comparing 'stupid' with 'stpid': 91%
  24. Comparing 'stupid' with 'upid': 80%
  25. Comparing 'stupid' with 'stuuupid': 86%
  26. Comparing 'stupid' with 'sstuuupiiid': 71%
复制代码

php, similar


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn