/** * calculate the difference between 2 strings * * @param string $a * @param string $b * @param float $divisor for calculating the minimum required percentage of overlap * @return string a merged version of $a and $b, with deleted and inserted * portions indicated by <del></del> and <ins></ins> tags */ public static function diff($a, $b, $divisor = 3.0) { self::$divisor = $divisor; if ($a == $b) { return $a; } elseif (empty($a)) { return '<ins>' . $b . '</ins>'; } elseif (empty($b)) { return '<del>' . $a . '</del>'; } $lcs = StringDiff::longest_common_substring($a, $b); if (empty($lcs)) { return '<del>' . $a . '</del><ins>' . $b . '</ins>'; } $atripartite = StringDiff::tripartite($a, $lcs); $btripartite = StringDiff::tripartite($b, $lcs); $headdiff = StringDiff::diff($atripartite[0], $btripartite[0]); $taildiff = StringDiff::diff($atripartite[2], $btripartite[2]); return $headdiff . $lcs . $taildiff; }