The examples in this article describe how PHP compares similar strings. Share to everyone for your reference. The specific analysis is as follows:
This compares the similarity of two strings through the Similar_text function of PHP.
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$word 2compare = "stupid"; $words = Array (' stupid ', ' Stu and pid ', ' Hello ', ' foobar ', ' stpid ', ' upid ', ' stuuupid ', ' sstuuupiiid ',); while (the list ($id, $str) = each ($words)) {Similar_text ($str, $word 2compare, $percent); print "Comparing ' $word 2compare ' With ' $str ': "; Print round ($percent). "%n"; }/* results:comparing ' stupid ' with ' stupid ': 100% comparing ' stupid ' with ' Stu and PID ': 71% Comparing ' stupid ' with ' H Ello ': 0% comparing ' stupid ' with ' foobar ': 0% comparing ' stupid ' and ' stpid ': 91% comparing ' stupid ' with ' upid ': 80% Co Mparing ' stupid ' with ' stuuupid ': 86% comparing ' stupid ' with ' sstuuupiiid ': 71% */ |
I hope this article will help you with your PHP program design.