Skip to content

Instantly share code, notes, and snippets.

@HugoWen
Created August 10, 2017 07:54
Show Gist options
  • Save HugoWen/2e866acc97daac6b217f1ed12934c494 to your computer and use it in GitHub Desktop.
Save HugoWen/2e866acc97daac6b217f1ed12934c494 to your computer and use it in GitHub Desktop.
php export csv file
function exportCSV($filename, $data)
{
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header("Content-Disposition:attachment;filename=".$filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo "\xEF\xBB\xBF"; // UTF-8 BOM
echo $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment