Return to Snippet

Revision: 48526
at July 4, 2011 18:06 by dsoms


Updated Code
<?php 

$data = "Some utf-8 characters ąćżźćł" 

header("Content-Type: application/octet-stream"); 
header("Content-Transfer-Encoding: binary"); 
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 
header('Content-Disposition: attachment; filename = "Export '.date("Y-m-d").'.tsv"'); 
header('Pragma: no-cache'); 

//these characters will make correct encoding to excel 
echo chr(255).chr(254).iconv("UTF-8", "UTF-16LE//IGNORE", $data); 

?>

Revision: 48525
at July 4, 2011 18:04 by dsoms


Updated Code
<?php 

$data = "Some utf-8 characters ��żź��" 

header("Content-Type: application/octet-stream"); 
header("Content-Transfer-Encoding: binary"); 
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 
header('Content-Disposition: attachment; filename = "Export '.date("Y-m-d").'.tsv"'); 
header('Pragma: no-cache'); 

//these characters will make correct encoding to excel 
echo chr(255).chr(254).iconv("UTF-8", "UTF-16LE//IGNORE", $data); 

?>

Revision: 48524
at July 4, 2011 18:03 by dsoms


Initial Code
<?php 

$data = "Some utf-8 characters ąćżźćł" 

header("Content-Type: application/octet-stream"); 
header("Content-Transfer-Encoding: binary"); 
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 
header('Content-Disposition: attachment; filename = "Export '.date("Y-m-d").'.tsv"'); 
header('Pragma: no-cache'); 

//these characters will make correct encoding to excel 
echo chr(255).chr(254).iconv("UTF-8", "UTF-16LE//IGNORE", $data); 

?>

Initial URL
http://www.php.net/manual/en/function.iconv.php#104287

Initial Description
If you want to export some utf-8 data into csv/tsv that will be readable by excel with correct encoding you must add special non vissable characters at the begining of file

Initial Title
Export UTF-8 data in excel with correct encoding

Initial Tags
excel

Initial Language
PHP