tags:

views:

38

answers:

2

I'm looking for a PHP library that will provide me inline diffing between two strings, like this: http://grabby.info/dfe2835f606443757ae7c18404e71781.png.

I'm using xdiff currently, but it's crossing out the entire line when a single word changes, and that's not what I want.

Any suggestions?

A: 

Try this one.

Diff implemented in pure php, written from scratch.

Byron Whitlock
Hi, thanks for the link. I don't think this is what I described, as I get this: "1c1 < this is the old string --- > this is the new string". I want it to be more like this: "1c1 < this is the <del>old</del> string --- > this is the <ins>new</ins> string".
Chad Johnson
+1  A: 

I used xdiff for this to highlight changes in the text of an html page. The basic workflow was:

  1. escape all html entities
  2. split html tags onto their own lines (append \n after the closing >)
  3. split the resulting text on whitespace (eliminating duplicate whitespace)
  4. rejoin the results of the previous split with \n as the seperator, so now all tags and words are on seperate lines
  5. do the diff with xdiff_string_diff()
  6. Patch up the diff output to highlight the additions/deletions with the appropriate tags

not particularly efficient, and very top-heavy on extra wrapping tags if you've got a long sequence of ads/deletions, but it did the job.

Marc B
Hmm, I will definitely try this. This seems like a good, creative solution that could definitely solve my problem. Thanks for posting.
Chad Johnson