开发者

What is a PHP library that will show inline diffs?

I'm looking for a PHP library that will provide me inline diffing between two st开发者_如何学运维rings, 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?


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 \nas the separator, so now all tags and words are on separate lines
  5. do the diff with [xdiff_string_diff()][1]
  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜