[SHARE] Compare Two Files and Find the Difference - PHP Script

Repulsor

Senior Member
Joined
Jun 11, 2013
Messages
904
Reaction score
357
Hey all,

Well, I coded this out to help SpecialOne from this thread :

http://www.blackhatworld.com/blackh...text-files-output-difference-windows-7-a.html He insists that I make a thread do this can be useful for many.

So here is the code :

Just save your first file as file1.txt and second one as file2.txt
PHP:
<?php
//load the text files
$data1 = file("file1.txt");
$data2 = file("file2.txt");

function flip_array_diff_key($b, $a) {
$at = array_flip($a);
$bt = array_flip($b);
$d = array_diff_key($bt, $at);
return array_keys($d);
}

//call the function
$cleandata = flip_array_diff_key($data1,$data2);
echo sizeof($cleandata)." Lines";
//write to text file
$file = fopen("cleandata.txt","w+");
foreach($cleandata as $data){
fwrite($file,$data);
}
The results would be saved in cleandata.txt

P.S : The script is pretty basic and explains itself(if someone wants to know.). Actually, this should have been a desktop bot. I am still learning Vb.net, so maybe I will be able to get a bot out.
 
Thx man! It really helped me! I hope many members will benefit from this too. Once again thx for your FREE share.
 
Hey all,

Well, I coded this out to help SpecialOne from this thread :

http://www.blackhatworld.com/blackh...text-files-output-difference-windows-7-a.html He insists that I make a thread do this can be useful for many.

So here is the code :

Just save your first file as file1.txt and second one as file2.txt
PHP:
<?php
//load the text files
$data1 = file("file1.txt");
$data2 = file("file2.txt");

function flip_array_diff_key($b, $a) {
$at = array_flip($a);
$bt = array_flip($b);
$d = array_diff_key($bt, $at);
return array_keys($d);
}

//call the function
$cleandata = flip_array_diff_key($data1,$data2);
echo sizeof($cleandata)." Lines";
//write to text file
$file = fopen("cleandata.txt","w+");
foreach($cleandata as $data){
fwrite($file,$data);
}
The results would be saved in cleandata.txt

P.S : The script is pretty basic and explains itself(if someone wants to know.). Actually, this should have been a desktop bot. I am still learning Vb.net, so maybe I will be able to get a bot out.

Hi! thank you for this good share. this might help me on my future projects. Best of luck mate.
 
Dude! I have been looking for this exact script for about a year. The amount of times I have needed this is insane. Thanks!
 
I haven't bothered to read through your code and don't mean to step on any toes but google "ExamDiff" if you need to compare two text files and find differences.
 
Back
Top