9

Comparing must work on-the-fly, so this must be done via javascript or with php (will make javascript ajax request).

What I need is probably advanced difference showing, so it will be probably best if there is any kind of good supported library.

This picture shows exactly what I need >

Tortoise Merge

Added #1: I found this http://ejohn.org/projects/javascript-diff-algorithm/ (example http://www.djsipe.com/js-diff/) which is ok, but doesn't support multiline? and it changes the whole word when only one character is different...

Added #2: I tested php script ( https://github.com/paulgb/simplediff/ ) but it has flaws.

Added #3: I found what i was looking for ( http://code.google.com/p/google-diff-match-patch/ )

Glavić
  • 42,781
  • 13
  • 77
  • 107
  • possible duplicate of [Highlight the difference between two strings in PHP](http://stackoverflow.com/questions/321294/highlight-the-difference-between-two-strings-in-php) – GWW Jan 05 '11 at 22:56
  • 1
    as you can see, the question on the link you gave me, is 2 years old, and the answer, that was accepted, has broken link (i already commented on that answer this afternoon). – Glavić Jan 05 '11 at 23:02

2 Answers2

8

This answer to a related question seems promising for javascript. google-diff-match-patch

It provides an API which will take care of all the complex and well known algorithms. However you'll have to do some work with the presentation.

PHP is more versatile there is a lot of diff tools out there. Look this other related question Calculate text diffs in PHP.

Community
  • 1
  • 1
mmarinero
  • 365
  • 1
  • 4
  • Tnx, I think that this > http://neil.fraser.name/software/diff_match_patch/svn/trunk/demos/demo_diff.html > is what I need. Will test this any report. – Glavić Jan 05 '11 at 23:26
  • tested it and this is exactly what I need. tnx! – Glavić Jan 06 '11 at 09:03
  • I went through this and ended up creating a wrapper library to help with the "presentation work" needed to use `diff_match_patch`: https://github.com/arnab/jQuery.PrettyTextDiff – or9ob Jan 24 '13 at 09:41
1

See Highlight the difference between two strings in PHP

Community
  • 1
  • 1
julesj
  • 754
  • 4
  • 10
  • as you can see, the question on the link you gave me, is 2 years old, and the answer, that was accepted, has broken link (i already commented on that answer this afternoon). – Glavić Jan 05 '11 at 23:03
  • @glavic There are a couple of answers in the thread. This one looks pretty promising: https://github.com/paulgb/simplediff/blob/5bfe1d2a8f967c7901ace50f04ac2d9308ed3169/simplediff.php – julesj Jan 05 '11 at 23:06
  • already tested that script or should we call it 2 functions. it doesn't work like i need. example: if I only add a new line, it returns the bad difference... – Glavić Jan 05 '11 at 23:16