PHP:将 MySQL 数据导出到 Excel 文件时出现问题 [英] PHP: Issue while exporting MySQL data into an Excel file
本文介绍了PHP:将 MySQL 数据导出到 Excel 文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 MySQL 数据导出到一个 Excel 文件中,该文件包含印地语"数据,但出现了印地语निमà¥à¤¨.
I am exporting MySQL data into an Excel file which contains "Hindi" data but in place of Hindi निमà¥à¤¨ is appearing.
请帮助解决我的问题.我的 PHP 代码是:
Please help in resolving my issue. My PHP code is:
<?php
include 'connection.php';
$filename = "currentaffairquestions"; //your_file_name
$file_ending = "xls"; //file_extention
mysqli_set_charset($conn,'utf8');
header("Content-Type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
$sep = "\t";
$sql="SELECT question_number,question_name,choice1,choice2,choice3,choice4,answer from current_affairs_question_details where id='$_GET[currentaffairid]'";
$result=mysqli_query($conn,$sql);
while ($property = mysqli_fetch_field($result)) { //fetch table field name
echo $property->name."\t";
}
print("\n");
while($row = mysqli_fetch_row($result)) //fetch_table_data
{
$schema_insert = "";
for($j=0; $j< mysqli_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
?>
推荐答案
mysqli_set_charset($con,"utf8");连接后立即
mysqli_set_charset($con,"utf8"); immediately after connection
这篇关于PHP:将 MySQL 数据导出到 Excel 文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文