I’ve been using similar_text
to compare two different strings, however instead of knowing how similar they are, I’d rather figure out exactly which part of the string doesn’t match the other.
For example:
$str1 = "The cat was happy";
$str2 = "The cat is happy";
custom_function($str1, $str2);
The function should return "is", since that is the only part of $str2
that doesn’t match $str1
.
Does anyone know of a way in PHP to do this?
Thanks.
3
Answers
You can split the strings into words and compare resulting arrays in next way:
php code online
Maybe this:
I am not sure what exactly did you mean, so this is another potential solution: