Compare the similarity of two strings through PHP's similar_text function

WBOY
Release: 2016-07-25 08:45:28
Original
1049 people have browsed it
Compare the similarity of two strings through PHP's similar_text function
  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% 'stupid' with 'stpid': 91%
  23. Comparing 'stupid' with 'upid': 80%
  24. Comparing 'stupid' with 'stuuupid': 86%
  25. Comparing 'stupid' with 'sstuuupiiid': 71%
Copy Code

php, similar

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template