For this purpose, there are two interesting native functions, Similar_text () and Levenshtein ()
Example similar_text ():
$string1 = 'AAAb'; $string2 = 'aaab'; similar_text ( $string1, $string2, $percentege ); echo $percentege . '%';
Example levenshtein ():
levenshtein($string1, $string2, 1, 1000, 1000000);
EDIT 1
Given that the first line always has the same number of entries as the second line, you can try the code below. I created two lines for testing purposes, the second line has two equal entries and 7 different entries for a total of 9.
$first_string = '253.0.0.1,253.0.0.2,253.0.0.3,253.0.0.4,253.0.0.5,253.0.0.6,253.0.0.7,253.0.0.8,253.0.0.9'; $second_string = '253.0.0.1,253.0.0.2,255.255.255.127,255.255.255.128,255.255.255.129,255.255.255.130,255.255.255.131,255.255.255.132,255.255.255.133'; $first_array = explode(',', $first_string); $second_array = explode(',', $second_string); $total_entries = count($first_array); $array_differences = array_diff($first_array, $second_array); $different_entries = count($array_differences); $percentage = ( $different_entries / $total_entries ) * 100 ; echo 'Difference: ' . round($percentage, 2) . '%';