[英]PHP - Differences between two pieces of text
I have two pieces of text! 我有两段文字! Every piece of text has some lines.
每段文字都有几行。 Every line contains any sort of char/numbers;
每行包含任何类型的字符/数字;
I'd like to implement a PHP function that will tell : 我想实现一个PHP函数,该函数将告诉:
Example : 范例:
Text 1 Text 2 Result my name is marco my name is marco OK I'm 25 I'm 26 Return 1 I like football I hate baseball Make newline on Text 2 I hate baseball I'm cold I'm cold OK
I tried many ways to do it, but I don't know how to identify if a line is NEW or if it's just edited. 我尝试了许多方法来完成此操作,但是我不知道如何识别行是新建的还是刚刚编辑的。 Maybe I should trace some index when user write the text?
也许当用户写文本时我应该追踪一些索引?
You could use the PEAR package that find differences trough the text: PEAR Text Diff 您可以使用PEAR包来查找文本中的差异: PEAR Text Diff
PEAR Text Diff: Engine for performing and rendering text diffs
PEAR Text Diff:用于执行和呈现文本差异的引擎
There's also Simple Diff which I don't personally know, IMO it's more trustable the PEAR package. 还有一个我个人不知道的简单差异 ,IMO,它是更可信赖的PEAR软件包。
Simple Diff: Given two arrays, the function diff will return an array of the changes.
简单差异:给定两个数组,函数差异将返回更改的数组。 I won't describe the format of the array, but it will be obvious if you use print_r() on the result of a diff on some test data.
我不会描述数组的格式,但是如果对某些测试数据进行比较的结果上使用print_r(),这将很明显。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.