Priti's Technical Corner

June 6, 2013

Horde_Text_diff Package


My research for the “Text_Diff” started with small requirement where in we are expected to track the changes made by authors in single content. This requirement is  very common in publishing industry, where multiple authors are editing the contents and moderator wants to track the changes.

“Text_Diff” is the common PHP pear package which is now  “Horde_Text_Diff”

I had a tough time making it work but finally I did and got some initial results

To install please follow the steps given at following

http://pear.horde.org/

I am considering you are able to install the package with a help of pear and pear is running all well at your machine.

require_once ‘Horde/Text/Diff.php’;
require_once ‘Horde/String.php’;
require_once ‘Horde/Text/Diff/Renderer.php’;
require_once ‘Horde/Text/Diff/Renderer/Inline.php’;
require_once ‘Horde/Text/Diff/Engine/Native.php’;
require_once ‘Horde/Text/Diff/Op/Base.php’;
require_once ‘Horde/Text/Diff/Op/Change.php’;
require_once ‘Horde/Text/Diff/Op/Copy.php’;

$from_text=file(./CH001.html’);   //Original File
$to_text=file(./CH001_edited_author.html’);  //Modified file
/* Create the Diff object. */
$diff = new Horde_Text_Diff(‘auto’, array($from_text,$to_text));

/* Output the diff in unified format. */
$renderer = new Horde_Text_Diff_Renderer_Inline();
echo $renderer->render($diff);
?>

The above code snippet will show you the changes . But, the challenge remain to see the changes in different colors to quickly identify that these are the edits.  When you will be working with Horde Package you will get lot of “Class not found” error which will make you add those files in your include section. Horde also comes with autoloader class which I would be exploring shortly :).

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: