How to get number of characters that two strings have in common in PHP

1 Answer

0 votes
$s1 = "abcdvopm";
$s2 = "AbCfwdvz";

$common = similar_text($s1, $s2, $percent);

echo $common . " characters in common" . "\n";

printf("that is %.2f%% of the string", $percent);
 
 
 
/*
run:
     
3 characters in common
that is 37.50% of the string
       
*/


answered Jun 13, 2014 by avibootz
edited Mar 19, 2025 by avibootz
...