Character-wise string diff in PHP

三世轮回 提交于 2020-01-01 03:30:09

问题


In short I am looking for something like google-diff-match-patch in PHP.

I have had a look at some similar questions at SO, and also at the algorithm provided here, but all of them fail:

diff("draßen", "da draußen")

should not give

<del>draßen</del> <ins>da draußen</ins> 

(which is kind of stupid for my purpose, because I want to compare file names), but (try here)

<ins>da </ins>dra<ins>u</ins>ßen

Is there a code snippet in PHP that does this? Unfortunately, I cannot use (i.e. install) external packages.


回答1:


https://github.com/gorhill/PHP-FineDiff supports character-wise diff and can render the differences in HTML




回答2:


The PEAR Package Text_Diff provides Inline-Diffs.




回答3:


There is a php version of google-diff-match-patch available here: https://github.com/nuxodin/diff_match_patch-php




回答4:


There is a port of fresh version google-diff-match-patch library. It is much faster than previous and have no problems wth utf8.



来源:https://stackoverflow.com/questions/3307292/character-wise-string-diff-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!