First off, this is an exact duplicate of these four questions:
- Highlight the difference between two strings in PHP
- JavaScript based diff utility
- How to do text DIFF using PHP?
- Calculate text diffs in PHP
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):
- https://github.com/nuxodin/diff_match_patch-php
- http://pear.php.net/package/Text_Diff
- https://github.com/paulgb/simplediff/blob/5bfe1d2a8f967c7901ace50f04ac2d9308ed3169/simplediff.php
- http://www.raymondhill.net/finediff/viewdiff-ex.php
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 why?). I would use the PEAR version if it is my only choice but I want to use the upto date package.
Does anyone know of a well used and currently maintained or built in function (even if it is a PHP extension) text diff for PHP and/or JavaScript (JQuery as well)?
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_diffand they use it in its new form on the horde channel. It seems thattext_diffis 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:
In
CCodeGeneratorfor their Gii module ( http://www.yiiframework.com/doc/api/1.1/CCodeGenerator/ ). The important part is where they actually hook into the PEAR module:By reading in the contents of two files which produces a
diffedoutput.Originally I did not want to use PEAR because of the bloat but this module is quite slim for a fully featured
text_diffso I have decided to go with this. Not only that but, at the moment, it is the onlytext_diffmodule that has truly worked for me so I am keeping with the best, even if the best is quite memory hungry.