root/modules/branches/2.10/endpointman/includes/pear_diff/docs/examples/diff.php

Revision 14126, 0.9 kB (checked in by tm1000, 1 year ago)

Endpoint Manager
-Add pear_diff

  • Property svn:eol-style set to native
Line 
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
12 require_once 'Text/Diff.php';
13 require_once 'Text/Diff/Renderer.php';
14 require_once 'Text/Diff/Renderer/unified.php';
15
16 /* Make sure we have enough arguments. */
17 if (count($argv) < 3) {
18     echo "Usage: diff.php <file1> <file2>\n\n";
19     exit;
20 }
21
22 /* Make sure both files exist. */
23 if (!is_readable($argv[1])) {
24     echo "$argv[1] not found or not readable.\n\n";
25 }
26 if (!is_readable($argv[2])) {
27     echo "$argv[2] not found or not readable.\n\n";
28 }
29
30 /* Load the lines of each file. */
31 $lines1 = file($argv[1]);
32 $lines2 = file($argv[2]);
33
34 /* Create the Diff object. */
35 $diff = new Text_Diff('auto', array($lines1, $lines2));
36
37 /* Output the diff in unified format. */
38 $renderer = new Text_Diff_Renderer_unified();
39 echo $renderer->render($diff);
40
Note: See TracBrowser for help on using the browser.