André Amorim

Crafting Web Experiences

//

Export data to CSV file without Libraries

 "Nishit", 'l_name'=> "patel", 'mobile'=> "999999999", 'gender'=> "male");
  header("Content-type: application/csv");
  header("Content-Disposition: attachment; filename="test".".csv"");
  header("Pragma: no-cache");
  header("Expires: 0");

  $handle = fopen('php://output', 'w');
  fputcsv($handle, array("No","First Name","Last Name"));
  $cnt=1;
  foreach ($data as $key) {
      $narray=array($cnt,$key["f_name"],$key["l_name"]);
      fputcsv($handle, $narray);
  }
      fclose($handle);

Published date:

Modified date: