Skip to content

Instantly share code, notes, and snippets.

@marcaum54
Last active August 29, 2015 14:23
Show Gist options
  • Save marcaum54/afc90cbfa156194cac5a to your computer and use it in GitHub Desktop.
Save marcaum54/afc90cbfa156194cac5a to your computer and use it in GitHub Desktop.
Exemplo de como tratrar problema de encoding em arquivos .CSV
function csv($items)
{
$fileName = date('Y-m-d_H-i-s') . '.csv';
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
//BUGFIX - Adiciona o BOM
echo chr(255) . chr(254);
$output = "";
foreach($items as $item)
$output .= implode(",", $item) . PHP_EOL;
$output = iconv('UTF-8', 'UTF-16LE//IGNORE', $output);
die($output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment