Re: Comparing 2 files
| From: | Raditha Dissanayake | Date: | Sun, 21 Mar 2004 00:55:39 +0000 |
| Subject: | Re: Comparing 2 files | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181058@lists.php.net to get a copy of this message | ||
You are reinventng the wheel try
diff file1 file2;
Jens Schmeiser wrote:
Dear list. I want to compare two text files and print the differences. The text files contain the structure of a database, so they are very big (>6000 lines). The file looks like that: TABLENAME#COLUMNNAME#DATATYPE#DATALENGTH#DATAPRECISION#NULLS ... I only check if the datatype and nulls are different. If so, then the two lines of the files will be printed. I tried to do that and it works excellent if there aren't many differences, but if there are many diffs, it takes time and time. What I do now is to read the to files to an array and get the differences with array_diff $array1=file('file1.txt'); $array2=file('file2.txt'); $result1 = array_diff($array1,$array2); $result2 = array_diff($array2,$array1); After that I do the following: foreach ($result1 as $line1) { foreach ($result2 as $line2) { // compare the two lines and show the differences; continue; } } Is there a better way to do that (and of course faster)? Regards Jens-- Raditha Dissanayake. --------------------------------------------- http://www.radinks.com/print/upload.php SFTP, FTP and HTTP File Upload solutions