Exporting to CSV using PHP PDF Print E-mail
Written by martcon   
Monday, 05 July 2010 14:05

Often, users may wish to export data from a web page to a CSV file. The following outlines how this can be achieved using PHP:

<?php

// Set up the data. \n moves the data to the next row while commas split the data into cells.

$data = "\nTest Data 1, Test Data 2\n";

// Set up the Raw HTTP Header for diverting the output to a CSV file.

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"myfile.csv\"");

/* The output is now diverted to the CSV file when we echo the data. Users will be asked to open or save  the CSV file using the Internet Browser's download mechanism. */
echo $data;

?>

 

 
RocketTheme Joomla Templates