Re: Compare two TXT files
| From: | Paul Chvostek | Date: | Sun, 18 Jul 2004 01:26:06 +0000 |
| Subject: | Re: Compare two TXT files | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190868@lists.php.net to get a copy of this message | ||
On Sat, Jul 17, 2004 at 07:07:44PM -0600, C.F. Scheidecker Antunes wrote:
>
> Is there a more efficient way to compare 2 TXT files other than reading
> line by line ?
>
> What I was doing was reading line by line and compare both files, if one
> line is different the loops are interrupted and the function returns true.
>
> Any ideas?
If all you're trying to do is determine whether the files are different,
and the files are relatively small, then it might be easiest to do
something like:
function filediff($foo, $bar) {
$f_foo = file_get_contents($foo);
$f_bar = file_get_contents($bar);
return ($f_foo == $f_bar);
}
Note that this has the opposite return value of your existing function:
it returns true if the files are THE SAME, like the unix "diff" command.
Alternately, if you want to know what differences exist between files,
you could load the files into arrays with the file() function, then use
the array_diff() function to spit out a list of lines in one file but
not the other.
Or, you could tell us more about what you're actually trying to do. :)
p
--
Paul Chvostek <paul@it.ca>
Operations / Abuse / Whatever
it.canada, hosting and development http://www.it.ca/