Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Compare two files for changes

    My goal is to compare two files with the same name and determine what the differences are between the newer and the older file so I can update the older file to match the newer one. I hope that makes sense.

    Currently Im just trying to figure out a good way to parse two files and determine what the changes are without loading the entire files into memory via the file() function; I would prefer to use a while loop with fread and feof if possible to reduce the amount of memory needed during the calculations.

    Anyone have any ideas?

    Thanks!
    God helps those who help others.

  • #2
    New Coder
    Join Date
    Jan 2006
    Location
    California. USA
    Posts
    86
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by amir View Post
    My goal is to compare two files with the same name and determine what the differences are between the newer and the older file so I can update the older file to match the newer one. I hope that makes sense.

    Currently Im just trying to figure out a good way to parse two files and determine what the changes are without loading the entire files into memory via the file() function; I would prefer to use a while loop with fread and feof if possible to reduce the amount of memory needed during the calculations.

    Anyone have any ideas?

    Thanks!


    maybe use filesize and get the size of each file and if the file size of the newer one is different from the older one then take the contents of the file using fread and rewrite it to the older file

    PHP Code:

    <?
    $new1 
    filesize("newsite.html");
    $old1 filesize("oldsite.php");
    if(
    $new1 != $old1){
    $newsite "newsite.html";
    $oldsite "oldsite.php";
    $qr fopen($oldsite'w') or die("Could not open file");
    $qw fopen($newsite'r') or die("Could not open file");
    $read fread($qwfilesize($newsite));
    fwrite($qr$read);
    echo 
    "File has been successfully updated!";
    }else{
    echo 
    "Site already the same";
    }

    ?>

  • #3
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,083
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Is ExamDiff something you could use to compare your two files?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Guys!
    God helps those who help others.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •