PHP 中的文本版本控制,具有差异突出显示
如果您曾经在 StackOverflow 上编辑过问题,您可能已经注意到它会跟踪问题所应用的确切更改。它以一种形式显示,突出显示文本中已删除的红色部分和自特定编辑以来添加的绿色部分。我的问题是如何自己实现这样一个系统。我正在尝试使用 PHP 和 MySQL 创建一个自定义 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?
Demonstration
Here I added some text which will show green if you click on the edit link to see the changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很确定我改变了其中的某些内容。除此之外,它应该可以完美地工作。
使用示例:
结果:
显然:
I'm pretty sure I changed something in it. Other than that, it should work perfectly.
Example of use:
And the result:
And visibly:
PEAR
Text_Diff
组件可能是这里很有帮助:它允许人们执行和渲染两个文本数据之间的差异。如果您查看 渲染器示例页面中,内联应该执行您想要的操作:在给定的示例中,它:
包围删除文本,并且和
包围添加的文本(
如果您使用一些 CSS 来设置这些文本的样式) ,你应该能够得到你所要求的。
The PEAR
Text_Diff
component might be helpful, here : it allows one to perform, and render, diffs between two text data.If you take a look at the Renderer examples page, the Inline one shoud do what you want : in the given example, it :
<del>
and</del>
<ins>
and</ins>
If you use a bit of CSS to style those, you should be able to get what you're asking for.