PHP 使用正确的编码导出excel中的UTF-8数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 使用正确的编码导出excel中的UTF-8数据相关的知识,希望对你有一定的参考价值。

<?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); 

?>

以上是关于PHP 使用正确的编码导出excel中的UTF-8数据的主要内容,如果未能解决你的问题,请参考以下文章