tags:

views:

55

answers:

3

Hi,

did you find a way to display differences between two htmls?? Im telling you I need to get this but I cant find a way to do this. There is a php class called daisdiff but it has no documentation at all whatsoever...

Please if you already implemented an alghoritm on some of your projects, pleas elet me know and five me some advice.

I really need to get this stuff done!

Many many thanks.

A: 

There is a UNIX program called diff which is meant just for that purpose. You use it like this:

diff -crB file1 file2

c stands for context. It shows some extra lines around the changed lines so that you can find them more easily.

r stands for recursive. That way you can specify directories as file1 and file2, with all the files therein being compared to each other, too.

B makes it ignore blank lines and their changes.

Let me go find the Windows solution just in case.

Franz
Oops. Looks like I forgot that PHP bit, eh? Just ignore this, then.
Franz
A: 

Here is a pure php implementation of diff, http://www.holomind.de/phpnet/diff.src.php. If you skip to the bottom of the page there is an example of how to use it.

stimms
+2  A: 

I advise you to use the pear Text_Diff package, the package come with some class and easy extensible, you can write your own "diff" renderer so it's easy to adapt and a lot more easy then parsing the output of the diff command.

here a short code snippet to compare two text files:

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

// define files to compare
$file1 = "data1.txt";
$file2 = "data2.txt";

// perform diff, print output
$diff = &new Text_Diff(file($file1), file($file2));
$renderer = &new Text_Diff_Renderer();
echo $renderer->render($diff);
RageZ