[英]Comparing text: what is the best approach
I have a database which stores sequential versions of a text file. 我有一个数据库,该数据库存储文本文件的顺序版本。 What I would like to do is allow the user to call up any two historical files (eg version 1 And version 4) and compare them for differences:
我想做的是允许用户调用任何两个历史文件(例如版本1和版本4)并比较它们之间的差异:
Basically an online GIT but for text files not code. 基本上是在线GIT,但文本文件不是代码。
I figure JavaScript is probably the best approach and I presume that there must be an open source library but I simply cannot find one. 我认为JavaScript可能是最好的方法,我认为必须有一个开源库,但我根本找不到。
Any assistance appreciated. 任何帮助表示赞赏。
If you are running under linux, you could install diff
, save both files in temp files, then compare them using the shell_exec
command. 如果您在linux下运行,则可以安装
diff
,将两个文件保存在临时文件中,然后使用shell_exec
命令进行比较。
For example 例如
$tmp1 = 'myfile.txt';
$tmp2 = 'myfile2.txt';
$output = shell_exec('diff -y {$tmp1} {$tmp2}');
Look at man diff
for an option that suits your needs. 在
man diff
寻找适合您需求的选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.