title: PHP generated CSV file has two blank lines at the top of the file
body: <p>I've a issue while generating CSV file using php (fputcsv function). CSV File data is fine but interms of formatting generated file has 2 blank lines at the top of the file. Not sure where it is coming from. Can someone help with this?</p>
  
  <p>var_dump($header); gives me below. here <strong>'x','x'</strong> is two blank lines at the top.</p>
  
  <pre><code>x
  x
      array(16) {
        [0]=&gt;
        string(14) "DataProviderID"
        [1]=&gt;
        string(12) "DataProvider"
        [2]=&gt;
        string(8) "FamilyID"
        [3]=&gt;
        string(10) "FamilyName"
        [4]=&gt;
        string(10) "SecurityID"
        [5]=&gt;
        string(4) "Name"
        [6]=&gt;
        string(10) "PrimaryRic"
        [7]=&gt;
        string(13) "Administrator"
        [8]=&gt;
        string(16) "IsAdminEULocated"
        [9]=&gt;
        string(21) "IsAdminOnEsmaRegister"
        [10]=&gt;
        string(25) "IsBenchmarkOnEsmaRegister"
        [11]=&gt;
        string(26) "IsBenchmarkOnAdminRegister"
        [12]=&gt;
        string(23) "HasEUListedFundTracking"
        [13]=&gt;
        string(25) "HasEUListedFutureOrOption"
        [14]=&gt;
        string(20) "IsAdminPre2016Active"
        [15]=&gt;
        string(24) "IsBenchmarkPre2018Active"
      }
      DataProviderID  DataProvider    FamilyID    FamilyName  SecurityID  Name    PrimaryRic  Administrator   IsAdminEULocated    IsAdminOnEsmaRegister   IsBenchmarkOnEsmaRegister   IsBenchmarkOnAdminRegister  HasEUListedFundTracking HasEUListedFutureOrOption   IsAdminPre2016Active    IsBenchmarkPre2018Active
      2   MSCI    36  MSCI Main Indices - Americas    17964   THE WORLD INDEX SMALL CAP-106230    .dMIWO000S0PUS  MSCI Limited    1   1   0   99  99  99  99  0
      2   MSCI    16730   MSCI Sector Indices - Europe Series 2   17996   EUROPE/OFFICE ELECTRONICS-106978    .dMIEU0OE00PUS  MSCI Limited    1   1   0   99  99  99  99  0
  </code></pre>
  
  <p>My code is as below:</p>
  
  <pre><code>&lt;?php 
  require_once '../upload/functions.php'; 
  
  $connectionInfo = getdb();
  #$connectionInfo = sqlsrv_connect(DB_HOST, $connectionInfo);
  
  if ($connectionInfo === false ) {
      die (print_r(sqlsrv_errors(), true));
  }
  
  $sql = "SELECT * FROM &lt;tablename&gt;;";
  $result = sqlsrv_query($connectionInfo, $sql);
  
  if (!$result) die ('Couldn\'t fetch records');
  
  $headers = array();
  
  foreach (sqlsrv_field_metadata($result) as $fieldMetadata) {
      $headers[] = $fieldMetadata['Name'];
  }
  
  #var_dump($headers);
  
  $fp = fopen('php://output', 'w');
  if ($fp &amp;&amp; $result) {
      header('Content-Type: text/csv');
      header('Content-Disposition: attachment; filename="KYBAttributes.csv"');
      header('Pragma: no-cache');
      header('Expires: 0');
     fputcsv($fp, array_values($headers),"\t");
      while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
          $row = str_replace('"', '', $row);
          fputs($fp, implode("\t", $row)."\n");       
      }
      die;
  }
  ?&gt;
  </code></pre>
  
  <p>Please note that closing php tag <strong>'?>'</strong> is not the issue here.</p>