1

I am trying to set up a class for tracking changes in the content by different authors. I did RnD and found text_Diff is the pear package which is responsible for the same. Later, text_diff is maintained at

'http://pear.horde.org/'

I am now trying to run the example

include_once "Text/Diff.php";
include_once "Text/Diff/Renderer.php";

$from_text=file('file.html');
$to_text=file('file_edited.html');

$diff = new Horde_Text_Diff($from_text, $to_text);
$renderer = new Horde_Text_Diff_Renderer();
echo $renderer->render($diff);

and I am getting the error 'Horde_String'

I am not able to find class, any one has idea about this class?. There are multiple Engine like "Native","XDiff","String" and "Shell" ...but I am not able to find what are they and when you use which one..

any help to resolve this error will be a great help.

Thanks

user269867
  • 3,266
  • 9
  • 45
  • 65

2 Answers2

0

I struggled for hours trying to get this to work. In the end I had to install Horde_Text_Diff by entering the commands (installs the Autoloader described in the linked question in the comment by Keelan):

pear install Horde_Autoloader pear install Horde_Text_Diff

This installs the packages I believe you need. Then, you need to properly call the autoloader package by tweaking the following code to match the paths for your system.

require_once 'Horde/Autoloader.php';
require_once 'Horde/Autoloader/ClassPathMapper.php';
require_once 'Horde/Autoloader/ClassPathMapper/Default.php';

$autoloader = new Horde_Autoloader();
$autoloader->addClassPathMapper( new Horde_Autoloader_ClassPathMapper_Default('/usr/share/pear') );
$autoloader->registerAutoloader();

Then, if all goes well you should be able to call and use the class by doing something like the following:

$check_diff = new Horde_Text_Diff( $engine = 'auto', $params = array( $from_text, $to_text ) );
$renderer = new Horde_Text_Diff_Renderer_Inline();
echo $renderer->render($check_diff);

Although this isn't totally working for me yet as I'm finding that it only compares the first characters in the strings. Which is a new problem unrelated to getting the class to work :)

James Huckabone
  • 615
  • 1
  • 12
  • 32
0

Here is my approach, which does not use the Hoard autoloader:

spl_autoload_register(function ($class_name) {
    if (substr($class_name, 0, strlen('Horde_')) != 'Horde_')
        return false;

    $file = substr($class_name, strlen('Horde_')); // omit if not needed
    $file = str_replace("_", DIRECTORY_SEPARATOR, $file);
    return include_once($file . '.php');
});

function diff($old, $new)
{
    $td = new Horde_Text_Diff('auto', array($old, $new));
    $rend = new Horde_Text_Diff_Renderer_Unified();
    return $rend->render($td);
}
nyet
  • 482
  • 2
  • 13