TextDiff.php 537 B

12345678910111213141516171819202122
  1. <?php
  2. error_reporting(E_ALL);
  3. Yii::import('gii.components.Pear.*');
  4. require_once 'Text/Diff.php';
  5. require_once 'Text/Diff/Renderer.php';
  6. require_once 'Text/Diff/Renderer/inline.php';
  7. class TextDiff extends CComponent
  8. {
  9. public static function compare($lines1, $lines2)
  10. {
  11. if(is_string($lines1))
  12. $lines1=explode("\n",$lines1);
  13. if(is_string($lines2))
  14. $lines2=explode("\n",$lines2);
  15. $diff = new Text_Diff('auto', array($lines1, $lines2));
  16. $renderer = new Text_Diff_Renderer_inline();
  17. return $renderer->render($diff);
  18. }
  19. }