Ejemplo n.º 1
0
 static function formatDiffAsHTML($before, $after, $mode = "w")
 {
     if (!self::diff($before, $after, $mode)) {
         return false;
     }
     $html = '';
     $td = count(self::$diff);
     for ($d = 0; $d < $td; ++$d) {
         $diff = self::$diff[$d];
         switch ($diff['change']) {
             case '=':
                 $html .= nl2br(htmlSpecialChars(substr($before, $diff['position'], $diff['length'])));
                 break;
             case '-':
                 $html .= '<del class="diff">' . nl2br(htmlSpecialChars(substr($before, $diff['position'], $diff['length']))) . '</del>';
                 break;
             case '+':
                 $html .= '<ins class="diff">' . nl2br(htmlSpecialChars(substr($after, $diff['position'], $diff['length']))) . '</ins>';
                 break;
             default:
                 self::$error = $diff['change'] . ' is not an expected difference change type';
                 return false;
         }
     }
     return self::$diff_html = self::purifyHTML($html);
 }