کد PHP:
function similar_check ($str1, $str2) {
$str1_len = mb_strlen($str1, 'UTF-8');
$str2_len = mb_strlen($str2, 'UTF-8');
if ($str1_len > $str2_len) {
$big_str = $str1;
$small_str = $str2;
}
else {
$big_str = $str2;
$small_str = $str1;
}
$length = 0;
$big_arr = explode (" ", $big_str);
$small_arr = explode (" ", $small_str);
$big_count = count ($big_arr);
$small_count = count ($small_arr);
$same_found = 0;
foreach($small_arr as $word)
{
$word = trim($word);
foreach($big_arr as $word2)
{
$word2 = trim($word2);
if($word == $word2) $same_found++;
}
}
$length = $big_count + $small_count;
var_dump($length, $same_found);
$percent = ($same_found*100)/$length;
return $percent;
}