• 技术文章 >PHP >PHP教程

    php导入时设置不同的编码

    小妮浅浅小妮浅浅2021-02-26 14:27:15原创3649

    我们经常在导入文件的时候会发现,原本正常的数据,加载到别的地方就发生了乱码,这对于我们的导入使用是非常不方便的。本篇主要针对的是两种编码utf8和gbk,一般来说在这两点上容易出错。下面我们就这两种不同编码的解决方法,分别带来介绍,一起来看看如何设置吧。

    php导入到excel-支持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表格做网页的就可以了。

    以上就是php导入时设置不同编码的方法,大家可以就这两种编码分别进行设置,然后在导入表格中,看看是否解决了乱码的问题。更多php学习指路:php教程

    专题推荐:php 编码
    品易云
    上一篇:php kohana框架设置路由 下一篇:php接口中interface的使用方法

    相关文章推荐

    • php中kohana框架是什么?• php中array_reverse()函数的翻转• php之kohana框架的安装详解• php kohana框架设置路由• PHP array_combine()函数创建数组• PHP中array_chunk() 函数如何分割数组

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网