title: Php explode function returning empty values
body: <p>I am trying to read data from a comma separated text file called test.txt using PHP. The file contents is as follows:</p>
  
  <pre><code>Sel,10,5,4
  Tati,5,6,7
  Vinny,10,10,10
  </code></pre>
  
  <p>I tried to read these values using a loop with fgets(), which is used to print line by line and fgets() and explode(), which are supposed to write element per element in each line.</p>
  
  <pre><code>&lt;?php
      $file=fopen('test.txt','r');
  
      if(!$file)
      {
          echo "Error reading file";
          die;
      }
  
      echo"Reading Line by Line";
  
      while(!feof($file))
      {
            $pointer=fgets($file,4096);
            echo "&lt;p&gt;".$pointer."&lt;p&gt;";    
      }
  
      rewind($file);
  
      echo "Reading value by value per line";
  
      while(!feof($file))
      {
            $pointer=fgets($file,4096);
            $pieces = explode(",", $pointer);
            echo"&lt;hr&gt;";
            echo "&lt;p&gt; Name:".$pieces[0]."&lt;p&gt;";
            echo "&lt;p&gt; Grade 1:".$pieces[1]."&lt;p&gt;";
            echo "&lt;p&gt; Grade 2:".$pieces[2]."&lt;p&gt;";
            echo "&lt;p&gt; Grade 3:".$pieces[3]."&lt;p&gt;";
            echo"&lt;hr&gt;";
      }   
      fclose($file);
  ?&gt;
  </code></pre>
  
  <p>However, when I use fgets() and explode() functions in php there is a  line printed with no values. This is strange, as I have only three lines in my text file and when I use fgets() without explode() it returns the values in the correct number of lines.</p>
  
  <p>What is wrong in this code?</p>
  
  <p><strong>Edit:</strong> here is my <a href="http://www.ic.unicamp.br/~anselmoferreira/le_csv.txt" rel="nofollow">code</a></p>