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.
$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 ' hello ': 0% comparing ' stupid ' and ' foobar ': 0% comparing ' stupid ' with ' stpid '
: 91%
comparing ' stupid ' with ' upid ': 80%
comparing ' stupid ' and ' stuuupid ': 86% comparing ' stupid ' with ' sstuuup
IIId ': 71%
*
I hope this article will help you with your PHP program design.