When we want to compare some sentences or the content of the similarity or matching degree, it will inevitably use the similar_text () This function, the following for this function to do a code demonstration
I created 6 sentences, and used the symbol, and then the 22 contrast, it can be seen that the function is more than the letter, the other symbols can be compared, of course, as the last statement in the code area, compare the similarity of two sentences with a percentage, the code is as follows:
$a = "HELLO,AA";
$b = "HELLO,BB";
echo "First code demo:";
Echo similar_text ($a, $b);
$c = "HELLOAA";
$d = "Hellobb";
echo "A second code demo:";
Echo Similar_text ($c, $d);
echo "\ n";
$e = "FEDCBA";
$f = "abcdef";
echo "A third code demo";
Echo Similar_text ($e, $f);
Similar_text ($c, $d, $percent);
echo "Fourth code demo:";
Echo $percent;
?>
Output results such as:
This time we will find a problem, that is, the third code area shows 1, and obviously, if the output should be 6 regardless of the order, in order, the result should be 0, how can be one, we further demonstrate:
$e = "AB";
$f = "ba";
echo "A third code further demonstrates:";
Similar_text ($e, $f, $percent);
echo $percent. " %";
?>
The result is:
Modify the following parameters:
$e = "ABCD";
$f = "DCBA";
echo "A third code further demonstrates:";
Similar_text ($e, $f, $percent);
echo $percent. " %";
?>
The result is |:
Regardless of how the proportions change, there is always a similar character present, viewed in the official literature, found that this function is based on the programming classics:implementing the world's Best Algorithms by Oliver (ISBN 0-131-00413-1) "The algorithm in this book is implemented, but at present I have no way to explain this problem, if you have any ideas can also say, thank you
The above describes the Php:similar_text function of the relevant analysis, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.