<button id="g80sy"></button>
  • <abbr id="g80sy"></abbr>
  • <button id="g80sy"></button>
    <rt id="g80sy"><delect id="g80sy"></delect></rt>
  • php導入時設置不同的編碼

    程序猿 2021-02-26 21:46:29 1878瀏覽 加載中

    我們經常在導入文件的時候會發現,原本正常的數據,加載到別的地方就發生了亂碼,這對于我們的導入使用是非常不方便的。本篇主要針對的是兩種編碼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
    最后修改:2025-07-12 16:42:06

    非特殊說明,本博所有文章均為博主原創。

    主站蜘蛛池模板: 灌南县| 建昌县| 宜宾县| 土默特右旗| 仙游县| 鄯善县| 静宁县| 扶余县| 灯塔市| 虎林市| 新蔡县| 周宁县| 万载县| 大兴区| 济南市| 平定县| 新余市| 多伦县| 佛冈县| 敦煌市| 南充市| 视频| 唐海县| 瓦房店市| 永登县| 鄂伦春自治旗| 靖州| 大关县| 玉溪市| 亳州市| 泰州市| 方山县| 彝良县| 竹山县| 许昌县| 临沧市| 宁晋县| 上犹县| 平顶山市| 治县。| 桂阳县|