Alex Rivera | Logout

PHP/JS Text Diff

Asked 2012-08-13T15:49:23.047
10

First off, this is an exact duplicate of these four questions:

It seems as though times have changed since these questions were first asked and I am wondering what is a good tool now-a-days for this sort of comparison? I have looked at (additionally to those questions):

But all of the ones I get are either unmantained now or seem a little dodgy in that they are not used that much (and some even hint that they are not very performant) and the PEAR one worries me. I hate to install PEAR for one little module not only that but it seems like throwing a brick through my own window to install it for such a small module in comparison to PEAR in general not only that but the module has been superseded and placed on a different channel (dunno

Edit
Report

1 Answer

2

Ok so it has been a while.

I actually decided to look around at what other people use and stumbled upon what Yii ( http://www.yiiframework.com ) uses.

They actually use the PEAR module for their text_diff and they use it in its new form on the horde channel. It seems that text_diff is now a horde project but you can just as easily integrate a version of it into your application and that is what Yii does by default (it comes pre-bundled with a version of it).

So I searched around a bit to find out how they used it and how to get into it and I came across:

public function actionDiff()
{
    Yii::import('gii.components.TextDiff');

    $model=$this->prepare();
    if(isset($_GET['id']) && isset($model->files[$_GET['id']]))
    {
        $file=$model->files[$_GET['id']];
        if(!in_array($file->type,array('php', 'txt','js','css')))
            $diff=false;
        elseif($file->operation===CCodeFile::OP_OVERWRITE)
            $diff=TextDiff::compare(file_get_contents($file->path), $file->content);
        else
            $diff='';

        $this->renderPartial('/common/diff',array(
            'file'=>$file,
            'diff'=>$diff,
        ));
    }
    else
        throw new CHttpException(404,'Unable to find the code you requested.');
}

In CCodeGenerator for their Gii module ( http://www.yiiframework.com/doc/api/1.1/CCodeGenerator/ ). The important part is where they actually hook into the PEAR module:

$diff=TextDiff::compare(file_get_contents($file->path), $file->content);

By reading in the contents of two files which produces a diffed output.

Originally I did not want to use PEAR because of the bloat but this module is quit

answered 2013-02-03T18:39:36.737

Your Answer