Home > Article > Backend Development > PHP imports utf8, gbk encoding into Excel_PHP tutorial
Import php to excel-supports both utf8 and gbk encodings
The reason why php imports garbled characters into excel is because utf8 encoding does not support all utf8 encoding in the xp system. It can be perfectly solved by transcoding
utf-8 encoding case
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=11.xls ");
header("Content-Transfer-Encoding: binary ");
?>
$filename="php import to excel-utf-8 encoding";
$filename=iconv("utf-8", "gb2312", $filename);
echo $filename;
?>
gbk encoding case
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=11.xls ");
header("Content-Transfer-Encoding: binary ");
?>
$filename="php import to excel-utf-8 encoding";
echo $filename;
?>
Download it to excel when you visit the website
If you want to distinguish between cells
Just use tables to make web pages