Skip to content

Instantly share code, notes, and snippets.

@twysto
Last active August 29, 2015 14:19
Show Gist options
  • Save twysto/5baec9934b54e456893d to your computer and use it in GitHub Desktop.
Save twysto/5baec9934b54e456893d to your computer and use it in GitHub Desktop.
public function exportCSV() {
$filename = 'export.csv';
$sep = chr(9); // ASCII 009 (Horizontal Tab)
$output = 'sep='.$sep."\n";
$output .= 'Email'.$sep.'Firstname'."\n";
$subscribers = $this->_dao->findNewsletterSubscribers(); // Query Database
foreach($subscribers as $subscriber) {
$output .= $subscriber['email'].$sep.$subscriber['firstname']."\n";
}
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
echo utf8_decode($output);
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment