duanmuyao0463 2013-09-30 04:06
浏览 64

将数据从SQL导出到Excel文件(csv)时出现未知的UTF-8

I'm going to export data from SQL to Excel file (csv). For now, i can exported data from SQL to Excel but it doesn't know Japanese language (it becomes ????? in Excel file that i export from SQL).

Here is data in SQL

ccode        country
AL           Albania
AD           Andorra
AO           Angola
BR           Brazil
JP           東京

Here is data in Excel file (csv) after i exported

ccode        country
AL           Albania
AD           Andorra
AO           Angola
BR           Brazil
JP           ????

Here is my coding to export data

<?php

//connection
include('dbconfig.php');

//create query to select as data from your table
$contents="ccode,country
";

//Mysql query to get records from datanbase
$user_query = mysql_query('SELECT * FROM countries');

//While loop to fetch the records
while($row = mysql_fetch_array($user_query))
{
    $contents.=$row['ccode'].",";
    $contents.=$row['country']."
";
}

// remove html and php tags etc.
$contents = strip_tags($contents); 

header('Content-type: application/vnd.ms-excel; charset=UTF-8');
header("Content-Disposition: attachment; filename=data".date('d-m-Y').".csv");
print $contents;

?>

Can anyone help me with this problem?

Thank in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大