PHP中的按字符排列的字符串差异 [英] Character-wise string diff in PHP

查看:37
本文介绍了PHP中的按字符排列的字符串差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之,我正在寻找PHP中的google-diff-match-patch。

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

我在SO上也看到过类似的问题,在此处处提供的算法,但它们均失败:

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")

应该给出

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

(这对我来说有点愚蠢,因为我想比较文件名),但是< a href = http://neil.fraser.name/software/diff_match_patch/svn/trunk/demos/demo_diff.html rel = nofollow noreferrer>(在此处尝试)

(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

PHP中是否有此功能的代码段?不幸的是,我不能使用(即安装)外部软件包。

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

推荐答案

https://github.com/gorhill/PHP-FineDiff 支持按字符区分,并且可以呈现HTML中的差异

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

这篇关于PHP中的按字符排列的字符串差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆