How to highlight changes/difference in one text paragraph from the other?

后端 未结 4 958
你的背包
你的背包 2021-01-21 04:03

Is it possible to highlight the modifications in one text paragraph from the other?

For example, there are 3 text fields in a database. Non-admin users can edit the text

4条回答
  •  爱一瞬间的悲伤
    2021-01-21 04:39

    This is an old thread but thought I'd catalog my findings.

    If you want to use raw php, this is by far the simplest, fastest, and most effective solution I've found: http://paulbutler.org/archives/a-simple-diff-algorithm-in-php/

    From what I can tell, the author of the above code is using an algorithm outlined in this article: http://www.codeproject.com/Articles/6943/A-Generic-Reusable-Diff-Algorithm-in-C-II

    Basic description of what's happening (taken from the article):

    • Find the current Longest Matching Sequence (LMS) of items.
    • Store this LMS in a results pile.
    • Process all data left above the LMS using recursion.
    • Process all data left below the LMS using recursion.

    Works like a charm!

提交回复
热议问题