Correlation Analysis of Php:similar_text function

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.