Highlight the difference between two strings in PHP

前端 未结 13 2846
独厮守ぢ
独厮守ぢ 2020-11-22 07:50

What is the easiest way to highlight the difference between two strings in PHP?

I\'m thinking along the lines of the Stack Overflow edit history page, where new text

13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 08:42

    Just wrote a class to compute smallest (not to be taken literally) number of edits to transform one string into another string:

    http://www.raymondhill.net/finediff/

    It has a static function to render a HTML version of the diff.

    It's a first version, and likely to be improved, but it works just fine as of now, so I am throwing it out there in case someone needs to generate a compact diff efficiently, like I needed.

    Edit: It's on Github now: https://github.com/gorhill/PHP-FineDiff

提交回复
热议问题