May 15, 2016
Using Array how to generate CSV File in PHP

Hi, friends in this tutorial I show you how to generate comma-separated value (CSV) file in PHP. CSV is the most generally supported format for transferring tabular data between applications. The ability to export data in CSV format is a useful feature for several programs and is becoming frequently common in web applications.
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php $info = array( "0" => array( "name" => "Mohan raj", "mobile" => "654564564" ), "1" => array( "name" => "Siva", "mobile" => "5645456465" ) ); $filename = 'empinfo.csv'; header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=$filename"); $output = fopen("php://output", "w"); $header = array_keys($info[0]); fputcsv($output, $header); foreach($info as $row) { fputcsv($output, $row); } fclose($output); ?> |
Download
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]