Renderer examples

Context renderer

<?php
require_once 'Text/Diff.php';
require_once 
'Text/Diff/Renderer/context.php';

$lines1 file('1.htm');
$lines2 file('2.htm');

$diff     = new Text_Diff('auto', array($lines1$lines2));
$renderer = new Text_Diff_Renderer_context();
echo 
$renderer->render($diff);
?>

generates the following output:

***************
*** 3,13 ****
   <head>
!   <title>PEAR Bug Tracking</title>
   </head>
   <body>
    <h1>PEAR Bug Tracking System</h1>
!   <div class="bug-box">
!    <h2>Report new Bug</h2>
!    <p>Got a test case?</p>
! 
!    <p>Reproducable steps?</p>
    </div>
   </body>
  </html>
--- 3,13 ----
   <head>
!   <title>PEAR Bug Tracker</title>
   </head>
   <body>
    <h1>PEAR Bug Tracking System</h1>
!   <div class="bug-box bug-box-first">
!    <h2>Report New Bug</h2>
!    <p>
!     Got a test case or reproducible steps?
!    </p>
    </div>
   </body>
  </html>

Inline renderer

<?php
require_once 'Text/Diff.php';
require_once 
'Text/Diff/Renderer/inline.php';

$lines1 file('1.htm');
$lines2 file('2.htm');

$diff     = new Text_Diff('auto', array($lines1$lines2));
$renderer = new Text_Diff_Renderer_inline();
echo 
$renderer->render($diff);
?>

generates the following output:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;PEAR Bug <del>Tracking&lt;/title&gt;</del><ins>Tracker&lt;/title&gt;</ins>
 &lt;/head&gt;
 &lt;body&gt;
  &lt;h1&gt;PEAR Bug Tracking System&lt;/h1&gt;
  &lt;div <del>class=&quot;bug-box&quot;&gt;</del><ins>class=&quot;bug-box bug-box-first&quot;&gt;</ins>
   &lt;h2&gt;Report <del>new</del><ins>New</ins> Bug&lt;/h2&gt;<del>
   &lt;p&gt;Got</del><ins>
   &lt;p&gt;
    Got</ins> a test <del>case?&lt;/p&gt;

   &lt;p&gt;Reproducable steps?&lt;/p&gt;</del><ins>case or reproducible steps?
   &lt;/p&gt;</ins>
  &lt;/div&gt;
 &lt;/body&gt;
&lt;/html&gt;

Unified renderer

<?php
require_once 'Text/Diff.php';
require_once 
'Text/Diff/Renderer/unified.php';

$lines1 file('1.htm');
$lines2 file('2.htm');

$diff     = new Text_Diff('auto', array($lines1$lines2));
$renderer = new Text_Diff_Renderer_unified();
echo 
$renderer->render($diff);
?>

generates the following output:

@@ -3,13 +3,13 @@
  <head>
-  <title>PEAR Bug Tracking</title>
+  <title>PEAR Bug Tracker</title>
  </head>
  <body>
   <h1>PEAR Bug Tracking System</h1>
-  <div class="bug-box">
-   <h2>Report new Bug</h2>
-   <p>Got a test case?</p>
-
-   <p>Reproducable steps?</p>
+  <div class="bug-box bug-box-first">
+   <h2>Report New Bug</h2>
+   <p>
+    Got a test case or reproducible steps?
+   </p>
   </div>
  </body>
 </html>
Introduction to Text_Diff (Previous) Usage examples (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.