Home > Backend Development > PHP Tutorial > Related analysis of php:similar_text function

Related analysis of php:similar_text function

WBOY
Release: 2016-07-28 08:27:04
Original
1218 people have browsed it

When we want to compare the similarity or matching degree of certain sentences or content, we will inevitably use the similar_text() function. Here is a code demonstration of this function

I created 6 sentences, and Use symbols and then compare them in pairs. It can be seen that this function compares more than just letters. Other symbols can also be compared. Of course, you can also use percentages to compare the similarity of two sentences like the last statement in the code area. , the code is as follows:

$a ="hello,aa";
$b ="hello,bb";
echo "The first code demonstration:";
echo similar_text($a, $b );
$c ="helloaa";
$d ="hellobb";
echo "Second code demonstration:";
echo similar_text($c, $d);
echo "n";
$e = "fedcba";
$f ="abcdef";
echo "The third code demonstration";
echo similar_text($e, $f);
similar_text($c, $d,$percent);
echo "No. Four code demonstrations: ";
echo $percent;
?>

The output result is as follows:

 php:similar_text函数的相关解析

 php:similar_text函数的相关解析

 php:similar_text函数的相关解析

 php:similar_text函数的相关解析

At this time we will find a problem, which is the third code The area displays 1, and it is obvious that if the order is ignored, the output result should be 6. Regardless of the order, the result should be 0. How can it be 1? Let us further demonstrate:

$ e ="ab";
$f ="ba";
echo "The third code further demonstrates:";
similar_text($e, $f,$percent);
echo $percent."%";
? >

The result is:

 php:similar_text函数的相关解析

Modify the parameters:

$e ="abcd";
$f ="dcba";
echo "The third code further demonstrates:";
similar_text($e, $f,$percent);
echo $percent."%";
?>

The result is |:

 php:similar_text函数的相关解析

No matter how the proportion changes, there is always a similar character. , I checked the official literature and found that this function is implemented based on the algorithm in the book "Programming Classics: Implementing the World's Best Algorithms by Oliver (ISBN 0-131-00413-1)", but I still have no way to explain it clearly. If you have any opinions on this issue, please share it. Thank you

The above introduces the relevant analysis of the php:similar_text function, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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