Q:

Find similarity of two strings in PHP

0

Find similarity of two strings in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

There is a function similar_text() in PHP, that can be used to find the similarity of two strings, this function accepts three parameters: 1) string1, 2) string2 and 3) percentpercent will have the percentage of the similar text.

<?php
    $str1 = "Welcome @ IncludeHelp";
    $str2 = "Welcome @ IncludeHelp";
    $str3 = "Welcome atIncludeHelp";
    
    //Here, $percent will store the percentage of the similarity
    similar_text($str1, $str2, $percent);
    echo "similarity b/w str1 and str2 is: $percent \n";
    
    similar_text($str2, $str3, $percent);
    echo "similarity b/w str2 and str3 is: $percent \n";
?>

Output

similarity b/w str1 and str2 is: 100
similarity b/w str2 and str3 is: 90.47619047619

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now