如何比较两个字符串并确定它们之间的差异?

I have two strings like this:

$str1 = "this is
         a text";

$str2 = "this is a text
         which is edited";

As you see there is two difference between them, removed that <br> which is after is (in the $str1) and appending whic is edited. Now I need to detect those difference, How can I do that?

Actually I need to show to my website's users what's edited. Something exactly like stackoverflow edit page (which highlights the difference with red and green colors).

$Diff = str_replace($srt1, "", $str2);

Should work

If you load the php extension xdiff, then the command xdiff_string_diff will make an unified diff containing the differences between two strings for you.

<?
$str1 = "this is
         a text";
$str2 = "this is a text
         which is edited";

$diff = xdiff_string_diff($str1, $str2, 1);
if (is_string($diff)) {
    echo "Differences between two strings:
";
    echo $diff;
}else{
    echo "The two strings look the same to me.";
}
?>