Last active
August 29, 2015 14:23
-
-
Save marcaum54/afc90cbfa156194cac5a to your computer and use it in GitHub Desktop.
Exemplo de como tratrar problema de encoding em arquivos .CSV
This file contains 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 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