vendredi 22 juillet 2016

Comparing two text files using PHP

I have a textfile created dynamically by running following lines of code.

 if (system('javac main.java 2>ErrorFile.txt')!==false)
    {
        exec('java main 1>OutputFile.txt<filename.txt');

    }}

I now want to compare

OutputFile.txt

with

sample.txt

. And i used the below function but it didn't help me. Can anyone help me out please!

 >  function filecomparision($a, $b) {
    > 
    >   if(filesize($a) !== filesize($b))
    >       return false;   $ah = fopen($a, 'rb');   $bh = fopen($b, 'rb');
    > 
    >   $result = true;   while(!feof($ah))   {
    >     if(fread($ah, 8192) != fread($bh, 8192))
    >     {
    >       $result = false;
    >       break;
    >     }   }
    > 
    >   fclose($ah);   fclose($bh);
    > 
    >   return $result; }

when i am tried the above function i got two differnt sizes for my files even though the content is same. And it's showing contents of OutputFile.txt as octal-content.

Aucun commentaire:

Enregistrer un commentaire