加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP导入编码的具体方法及代码指什么

发布时间:2023-05-26 13:49:59 所属栏目:PHP教程 来源:
导读:这篇文章主要介绍“PHP导入编码的具体方法及代码是什么”的相关知识,下面会通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“PHP导入编码的具体方法及代码是什么”文章
这篇文章主要介绍“PHP导入编码的具体方法及代码是什么”的相关知识,下面会通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“PHP导入编码的具体方法及代码是什么”文章能帮助大家解决问题。
 
我们经常在导入文件的时候会发现,原本正常的数据,加载到别的地方就发生了乱码,这对于我们的导入使用是非常不方便的。本篇主要针对的是两种编码utf8和gbk,一般来说在这两点上容易出错。下面我们就这两种不同编码的解决方法,分别带来介绍,一起来看看如何设置吧。
 
1、utf-8编码案例
 
php导入到excel乱码,是因为utf8编码在xp系统不支持所有utf8编码,转码一下就完美解决了。
 
<?php
 
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=www.niutw.com.xls ');
 
header('Content-Transfer-Encoding: binary ');
 
?>
 
<?
 
$filename='php导入到excel-utf-8编码';
 
filename=iconv('utf-8', 'gb2312',filename=iconv(
 

 
 utf−8
 

 
 ,
 

 
 gb2312
 

 
 ,filename);
 
echo $filename;
 
?>
 
2、gbk编码案例
 
<?php
 
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=www.iiwnet.com.xls ');
 
header('Content-Transfer-Encoding: binary ');
 
?>
 
<?
 
$filename='php导入到excel-utf-8编码';
 
echo $filename;
 
?>
 
访问网站的时候就下载到excel里面,要弄单元格区别的话,用table表格做网页的就可以了。
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!