PHP - Finding number of matching words between two pieces of text?
I want to find number of similar words between two texts Example $str1=the cat is on the roof $str2=the mouse is on the roof the,is,on,the,roof words are similar in $str1 and $str2 So output will be in number 5 OR In percentage 86% I am try similar_text() function but this function not work as which i want. Easy, explode them and then use array_diff: $totalWords = count($array_1); $array_1 = explode(" ", $str1); $array_2 = explode(" ", $str2); $differenceCount = count(array_diff($array_1, $array_2)); $differentPercent = $differenceCount / ($totalWords / 100); @Edit: Edited code above to