Help please to compare two strings and take the difference between them in percent
I had two strings like:
first string:
253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,253.0.0.0,247.0.0.24,197.0.0.35,189.0.0.98....
second string:
255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127,255.255.255.127....
$first_array = explode(",", $out_string);
$second_array = explode(",", $out_string_1);
$result_array = array_merge(array_diff($first_array, $second_array), array_diff($second_array, $first_array));
$result = implode(",",$result_array);
echo $result;
There are two interesting native functions for this purpose, similar_text() and levenshtein()
Example of similar_text():
Example of levenshtein():
EDIT 1
Considering that the first string always have the same quantity of entries that second string, you can try the below code. I’ve created two strings for test purpose, second string has two equal entries and 7 different entries in a total of 9.