tags:

views:

32

answers:

1

I've been trying to figure this one out for a bit... I even downloaded MediaWiki and looked at their diff script, but I couldn't make heads or tails out of it. I am making a content management system, that will have revision history saved on it. However, revision history is pointless unless you can analyze the difference. I have very simplistic needs beyond that, and a lot of systems out there are very complicated, and I am nowhere near smart enough to figure them out.

http://en.wikipedia.org/wiki/Help:Diff

I want to input two variables:

  • $old (which is the source code of the left)
  • $new (which is the source code of the right)

Then I want to receive back an array matrix of results. Each element of the array is a row, like what you see in the wikipedia link above. Each element should have 4 values...

  • $oldDiff (which will be the modifier of the left, usually blank, + or -)
  • $newDiff (which will be the modifier of the right, usually blank, + or -)
  • $oldLine (the line of text for the left)
  • $newLine (the line of text for the right)

Thats it... pretty simple results. I can analyze the array matrix myself and output the results within my script.

A: 

Have a look at the Pear Text_Diff package. It won't give you exactly the arrays you want, but it will give something you should be able to use. You may also want to look into the native UNIX diff utility, which will without doubt be faster than any native PHP method.

lonesomeday
I've look at Text_Diff before... and it confused me. I have absolutely no idea how to use it.
Jason Axelrod