title: PHP Comparing two CSV files and highlight the difference
body: <p>I want to compare two CSV files and highlight the difference where it occurs. At the moment I have a small script that reads both CSV files and prints out the content on to the browser. these files are structured the same in term of column number but the values in some rows are different and I would like to highlight this difference but not to sure where to start from: </p>
  
  <p>PHP Code:</p>
  
  <pre><code>&lt;?php
  $file = fopen("try.csv","r");
  $file2 = fopen("try2.csv", "r");
  
  if(! feof($file)){
  
      while($data = fgetcsv($file))
      {
          foreach($data as $element){
              echo $element.'   ';
          }
  
          echo '&lt;br /&gt;';
  
  
      }
  }
  
  echo '&lt;br /&gt;';
  echo "&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;New File&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;";
  echo '&lt;br /&gt;';
  
  if(! feof($file2)){
  
      while($data = fgetcsv($file2))
      {
          foreach($data as $element2){
              echo $element2.'   ';
          }
  
          echo '&lt;br /&gt;';
  
  
      }
  }
  
  
  fclose($file);
  ?&gt;
  </code></pre>
  
  <p>Knowing that the variables <code>$element</code> &amp; <code>$element2</code> hold the CSV content how can I find the differences....?</p>