title: download a csv file dynamically create in PHP
body: <p>how can I force the browser to download a csv file I created in PHP?</p>
  
  <p>I tried</p>
  
  <pre><code>$result = array (
     array('aaa', 'bbb', 'ccc', 'dddd'),
     array('123', '456', '789'),
     array('aaa', 'bbb')
  );
  
  $filename = 'result_file.csv';
  
  header("Content-Type: text/plain");
  header('Content-Disposition: attachment; filename="'.$filename.'"');
  header("Content-Length: " . strlen($result));
  echo $result;
  exit;
  </code></pre>
  
  <p>but the csv file is full of PHP errors</p>