Forum Moderators: coopster
I'm wondering if someone could help me out.
I'm trying to write a PHP script to compare MySQL entrys and bold/red out the differences in PHP..
I'll try to explain:
¦------------------------------------------
¦ database 1:
¦ id¦ string
¦ -----------------------------------------
¦ 1 ¦ I like to eat meat with potatoes
¦
¦------------------------------------------
¦
¦ database 2:
¦ id¦ string
¦ ------------------------------------------
¦ 1¦ I like to eat meat, and fish, with potatoes
¦------------------------------------------
Output after PHP/MySQL:
¦
¦ I like to eat meat, and fish, with potatoes
¦
I can only manage to compare if they strings in both databases are the same, but I can't manage to get the differences shown the way I want..
I hope someone understood what I want, and I hope someone could help me :) thanks
$str1 = 'I like to eat meat with potatoes';
$str2 = 'I like to eat test and meat, and fish, with potatoes and a nice drink potatoes ';
#
function diff($small, $large, $start, $end) {
$small .= ' ';
$diff = '';
$i = 0;
$j = 0;
$on = false;
for($i; $i < strlen($large); $i++) {
if($large[$i] == $small[$j]) {
if($on)
$diff .= $end.$large[$i];
else
$diff .= $large[$i];
$on = false;
#
if(isset($small[$j+1]))
$j++;
} else {
if(!$on)
$diff .= $start.$large[$i];
else
$diff .= $large[$i];
$on = true;
}
#
}
#
return trim($diff);
}
#
echo diff($str1, $str2, '<font size="+4">' , '</font>');