Forum Moderators: coopster

Message Too Old, No Replies

comparing 2 files

         

jackvull

2:13 pm on Jan 19, 2010 (gmt 0)

10+ Year Member



I have 2 files downloaded by curl and I would like to compare them.
They are supposed to be the same but the filesizes are different.
Any ideas on how to compare the HTML text in each?
Would an array hold all the data or is the HTML too long?

I was told Text_Diff might work but I don't want to spend the time installing pear if I can use native functions.

StoutFiles

2:47 pm on Jan 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$File1 = "File1.txt";
$File2 = "File2.txt";
$f1 = fopen($File1, 'r');
$Data1 = fread($f1, filesize($File1));
$f2 = fopen($File2, 'r');
$Data2 = fread($f2, filesize($File2));
fclose($f1);
fclose($f2);

if($Data1 == $Data2)
echo "same.";
else
echo "not same.";

File sizes could be different from spacing. If that's the case then parse out the spaces in the data before comparing.