b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_ext/phpsvnclient/ext/Diff/docs/examples/diff.php - 41 lines - 1000 bytes - Text - Print

Description: Text_Diff example script.

   1  #!/usr/bin/php
   2  <?php
   3  /**
   4   * Text_Diff example script.
   5   *
   6   * Take two files from the command line args and produce a unified
   7   * diff of them.
   8   *
   9   * @package Text_Diff
  10   */
  11  if( ! defined( 'EVO_MAIN_INIT' ) ) die( 'Please, do not access this page directly.' );
  12  
  13  require_once 'Text/Diff.php';
  14  require_once 'Text/Diff/Renderer.php';
  15  require_once 'Text/Diff/Renderer/unified.php';
  16  
  17  /* Make sure we have enough arguments. */
  18  if (count($argv) < 3) {
  19      echo "Usage: diff.php <file1> <file2>\n\n";
  20      exit;
  21  }
  22  
  23  /* Make sure both files exist. */
  24  if (!is_readable($argv[1])) {
  25      echo "$argv[1] not found or not readable.\n\n";
  26  }
  27  if (!is_readable($argv[2])) {
  28      echo "$argv[2] not found or not readable.\n\n";
  29  }
  30  
  31  /* Load the lines of each file. */
  32  $lines1 = file($argv[1]);
  33  $lines2 = file($argv[2]);
  34  
  35  /* Create the Diff object. */
  36  $diff = new Text_Diff('auto', array($lines1, $lines2));
  37  
  38  /* Output the diff in unified format. */
  39  $renderer = new Text_Diff_Renderer_unified();
  40  echo $renderer->render($diff);
  41  ?>

title

Description

title

Description

title

Description

title

title

Body