Compare 5000 strings with PHP Levenshtein

前端 未结 8 1672
长情又很酷
长情又很酷 2021-01-30 12:15

I have 5000, sometimes more, street address strings in an array. I\'d like to compare them all with levenshtein to find similar matches. How can I do this without looping throug

8条回答
  •  心在旅途
    2021-01-30 12:50

    $stringA = "this is php programming language";
    $stringB = "this is complete programming script in which java php and  all other minor languages include";
    
    echo "string 1---->".$stringA."
    "; echo "string 2---->".$stringB."
    "; // changing string to arrays $array1 = explode(' ', $stringA); $array2 = explode(' ', $stringB); // getting same element from two strings $c = array_intersect($array1, $array2); // changing array to the string $d=implode(' ',$c); echo "string same elements---> ".$d."
    "; // getting difrent element from two arrays $result = array_diff($array2, $array1); // changing array to the string $zem = implode(' ',$result); if (!empty($zem)) { echo "string diffrence---> ".$zem."
    "; } else { echo "string diffrence--->both strings are same
    "; } similar_text($stringA, $d, $p); echo " similarity between the string is ".$p."%
    ";

提交回复
热议问题