alex4544
asked on
Export php content to CSV
Hi I want a button on our page that exports the following line to CSV format as that is how it is generated
echo $location.",".$appt['first _name']." ".$appt['last_name'].",".$ apdate."," .$aptime." ,".$apptty pe.",".$te l.",2 <br/>";
The code generates something similar to
Home,John Smith,11/11/2009,18:30:00, Appt,07707 742558,2
echo $location.",".$appt['first
The code generates something similar to
Home,John Smith,11/11/2009,18:30:00,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
header('Pragma: public'); // required
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false); // required for certain browsers
header('Content-Type: application/vnd.ms-excel') ;
$date = date('Y_m_d');
$filename = strtolower(str_replace(' ', '_', $site['name'])).'_'.$date. '.xls';
header('Content-Dispositio n: attachment; filename='.$filename.';' );
header('Content-Transfer-E ncoding: binary');
header('Content-Length: '.strlen($output));
foreach ($apptResult as $appt) {
echo $location.",".$appt['first _name']." ".$appt['last_name'].",".$ apdate."," .$aptime." ,".$apptty pe.",".$te l.",2";
echo "\n";
}
exit;
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false); // required for certain browsers
header('Content-Type: application/vnd.ms-excel')
$date = date('Y_m_d');
$filename = strtolower(str_replace(' ', '_', $site['name'])).'_'.$date.
header('Content-Dispositio
header('Content-Transfer-E
header('Content-Length: '.strlen($output));
foreach ($apptResult as $appt) {
echo $location.",".$appt['first
echo "\n";
}
exit;
This is a snippet of code from something I use to export from a database. You'll probably need to make some minor adjustments to take into account the desired file name and the text you wish to output.
Open in new window