添加<;ins><;del>;标记,以便与PHP和HTML一起使用


Simple inline diff algorithm that adds <ins> <del> tags for use with PHP and HTML?

我以前尝试过Paul的简单差分算法,但效果很差。它甚至不能显示在字符串末尾只添加了几个字符,而不标记据称该字符串的某些部分已被删除。

我需要这样的东西:

string end
begin strngs
<ins>begin </ins>str<del>i</del>ng<ins>s</ins><del> end</del>

我试过了http://www.raymondhill.net/finediff/viewdiff-ex.php如果选择"字符"粒度,结果正是您想要的。

我认为一个好的diff算法很大程度上是基于启发式的。这取决于你有什么样的变化,以及你想如何表现它们。

例如:

The cat jumped over the fence
The panther jumped over the fence

您可以区分为:

The <del>c</del><ins>p</ins>a<ins>n</ins>t<ins>her</ins> jumped over the fence

或:

The <del>cat</del><ins>panther</ins> jumped over the fence

两者都是准确的(省略了我的任何错误)。