PHP 中的文本版本控制,具有差异突出显示 [英] Text version-control in PHP with difference highlight

查看:29
本文介绍了PHP 中的文本版本控制,具有差异突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您曾经在 StackOverflow 上编辑过问题,您可能已经注意到它会跟踪应用到问题的确切更改.它通过突出显示在特定编辑中删除的文本的红色部分和添加的绿色部分以一种形式显示.我的问题是如何自己实现这样的系统.我正在尝试使用 MySQL 在 PHP 中创建自定义 CMS,这似乎是一个非常酷的功能.

If you ever edited a question right here on StackOverflow, you have probably noticed that it keeps track of what exact changed were applied to a question. It is displayed in a form by highlighting red portion of a text which were removed and green which were added since at a particular edit. My question is how to implement such a system myself. I am trying to make a custom CMS in PHP with MySQL and this seems like a very cool feature to tackle.

有什么建议或者可能有已经可以做到这一点的开源库,我可以分析他们是如何做到的?

Any advice or maybe there are open source libraries which can do this already and I can just analyze how they do it?

演示

这里我添加了一些文本,如果您单击编辑链接查看更改,这些文本将显示为绿色.

Here I added some text which will show green if you click on the edit link to see the changes.

推荐答案

The PEAR Text_Diff 组件在这里可能会有所帮助:它允许执行和呈现两个文本数据之间的差异.

The PEAR Text_Diff component might be helpful, here : it allows one to perform, and render, diffs between two text data.


如果你看看 Renderer示例页面,内联应该做你想做的事:在给定的例子中,它:


If you take a look at the Renderer examples page, the Inline one shoud do what you want : in the given example, it :

  • 包围删除文本
  • 环绕添加的文本
  • surrounds delete text by <del> and </del>
  • surround added text by <ins> and </ins>

如果您使用一些 CSS 来设置样式,您应该能够得到您想要的.

If you use a bit of CSS to style those, you should be able to get what you're asking for.

这篇关于PHP 中的文本版本控制,具有差异突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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