Created
January 9, 2017 16:19
-
-
Save aiiddqd/d7ebe02d5772e8d475038681557bb52e to your computer and use it in GitHub Desktop.
Save array to CSV (for php and WordPress)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function save_data_to_file(){ | |
// output headers so that the file is downloaded rather than displayed | |
header('Content-Type: text/csv; charset=utf-8'); | |
header('Content-Disposition: attachment; filename=data.csv'); | |
$output = fopen('php://output', 'w'); | |
$data = array( | |
array('text1', 'text2'), | |
array('text1', 'text2') | |
); | |
foreach ($data as $item) { | |
fputcsv($output, $item); | |
} | |
fclose($output); | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment