Well, you could use [man]strcmp/man to figure out which string is longer, then do a str_replace or substr from the smaller to the larger and return what's left.
Something like:
<?php
function long_strcmp($string1, $string2)
{
$result = strcmp($string1, $string2);
if($result < 0) // string1 is shorter than string2
{
return str_replace($string1, '', $string2);
}
elseif($result > 0) // string 2 is shorter than string 1
{
return str_replace($string2, '', $string1);
}
else // They're the same, return an empty string
return '';
}
No guarantee that would work, but worth a shot. I know it won't work well when comparing two strings that are completely different.
The other alternative is to step through the string on a character by character basis and if they are different, then add them to a new string; otherwise, keep moving on. That would take a little longer with long strings though.