Step1: Create two files named file1.txt and file2.txt with the following contents
Apple
Orange
Mango
Pineapple
Jackfruit
Step2: use the below php file to compare the two text file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php $first_file_data=file_get_contents('file1.txt'); $first_data_line_by_line = explode("\n", $first_file_data); $second_file_data=file_get_contents('file2.txt'); $second_data_line_by_line = explode("\n", $second_file_data); $size_one=count($first_data_line_by_line); $size_two=count($second_data_line_by_line); $status=true; if($size_one!=$size_two) { echo "Files are not Equal"; } else { $i=0; foreach($first_data_line_by_line as $val) { if($val!=$second_data_line_by_line[$i]) { $status=false; break; } $i++; } if($status==true){echo "Files are Equal";}else{echo "Files are not Equal";} } ?> |