/** * get the diff as a single text string * * @param string original content * @param string updated content * @return an ASCII string */ public static function &sdiff(&$original, &$updated) { global $context; // compare the two sequences $sequence = Scripts::compare($original, $updated, 2000); // format the output string $text = ''; foreach ($sequence as $item) { list($tag, $left, $right) = $item; //comment out suppressed lines if ($tag == '-') { if (strncmp($left, '<', 1)) { $text .= ' <del>' . $left . '</del> '; } } elseif ($tag == '+') { if (strncmp($right, '<', 1)) { $text .= ' <ins>' . $right . '</ins> '; } else { $text .= $right . ' '; } } elseif ($right) { if ($right[0] != '<' && $text && $text[strlen($text) - 1] != '>') { $text .= ' '; } $text .= $right; } } // recombine added words $text = trim(str_replace(array('</del> <del>', '</ins> <ins>'), ' ', $text)); // return the result of the whole comparison return $text; }