About comparing 2 files, you can open each file, read character for character and compare them.
here is some code I have to read a file, I'm sure you can tweak it to fit your needs
function FileCompare() {
$file_data1 = fopen ("/path_to_file/file1.txt", "r");
$file_data2 = fopen ("/path_to_file/file2.txt", "r");
while (!feof ($file_data)) {
$record = fgets($file_data);
$ra = split( ',', $record);
//open other file and read/compare the characters
}
fclose($file_data);
}