简体   繁体   English

比较文字:什么是最好的方法

[英]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)并比较它们之间的差异:

  1. Spelling changes 拼写变更
  2. New words / new sentences / new paragraphs 新词/新句子/新段落
  3. Moved paragraphs 移动的段落
  4. Etc 等等

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM