1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'PHP & Perl' started by Repulsor, Oct 28, 2014.

  1. Repulsor

    Repulsor Power Member

    Joined:
    Jun 11, 2013
    Messages:
    712
    Likes Received:
    267
    Location:
    PHP Scripting ;)
    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.
     
    • Thanks Thanks x 3
  2. SpecialOne

    SpecialOne Registered Member

    Joined:
    Jan 12, 2011
    Messages:
    65
    Likes Received:
    21
    Thx man! It really helped me! I hope many members will benefit from this too. Once again thx for your FREE share.
     
  3. member8200

    member8200 Regular Member

    Joined:
    Aug 9, 2014
    Messages:
    469
    Likes Received:
    33
    Hi! thank you for this good share. this might help me on my future projects. Best of luck mate.
     
  4. facebookdude

    facebookdude Elite Member

    Joined:
    Feb 28, 2010
    Messages:
    1,507
    Likes Received:
    2,490
    Dude! I have been looking for this exact script for about a year. The amount of times I have needed this is insane. Thanks!
     
  5. natsirtdm

    natsirtdm Junior Member

    Joined:
    Jun 5, 2012
    Messages:
    121
    Likes Received:
    44
    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.