Skip to content

Instantly share code, notes, and snippets.

@Clivern
Created October 14, 2016 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Clivern/56fd7bfc1db0caded1e7bfd2a40e481f to your computer and use it in GitHub Desktop.
Save Clivern/56fd7bfc1db0caded1e7bfd2a40e481f to your computer and use it in GitHub Desktop.
CSV With UTF-8 Support
$results = [
['اسم المستخدم', 'اسم المستخدم', 'اسم المستخدم'],
[5,8,6],
[5,8,7],
[2,3,5]
];
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=sss.csv');
echo "\xEF\xBB\xBF"; // UTF-8 BOM
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, $results[0]);
unset($results[0]);
foreach ($results as $row) {
fputcsv($output, $row);
}
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment