title: write into csv file in php
body: <p>I have to create and write into a csv file. Now I tried with the following code:</p>
  
  <pre><code>header('Content-type: application/octet-stream');  
  header('Content-disposition: attachment; filename="data.csv"');    
  $data = array (
      'aaa,bbb,ccc,dddd',
      '123,456,789',
      '"aaa","bbb"');
  
  $fp = fopen('php://output', 'w+');  
  foreach($data as $line){
      $val = explode(",",$line);
      fputcsv($fp, $val);
  }
  fclose($fp);  
  </code></pre>
  
  <p>It gives me my source file code also in the csv file? How can I solve this?</p>