首頁 >後端開發 >PHP問題 >php中xls匯出亂碼怎麼辦

php中xls匯出亂碼怎麼辦

藏色散人
藏色散人原創
2022-11-24 09:20:031801瀏覽

php中xls導出亂碼的解決方法:1、開啟對應的PHP檔案;2、在產生亂碼的檔案中,加上「header("Content-type:application/vnd.ms-excel;charset =UTF-8");」語句即可。

php中xls匯出亂碼怎麼辦

本教學操作環境:Windows7系統、PHP8.1版、Dell G3電腦。

php中xls匯出亂碼怎麼辦?

採用phpmyadmin的處理方式 

<?php 
header("Content-type:application/vnd.ms-excel;charset=UTF-8"); 
header("Content-Disposition: attachment; filename=$filename"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
?> 
//这个很关键

相關介紹:

Content-type類型有

<?php
$mimetypes = array(
&#39;ez&#39; => &#39;application/andrew-inset&#39;,
&#39;hqx&#39; => &#39;application/mac-binhex40&#39;,
&#39;cpt&#39; => &#39;application/mac-compactpro&#39;,
&#39;doc&#39; => &#39;application/msword&#39;,
&#39;bin&#39; => &#39;application/octet-stream&#39;,
&#39;dms&#39; => &#39;application/octet-stream&#39;,
&#39;lha&#39; => &#39;application/octet-stream&#39;,
&#39;lzh&#39; => &#39;application/octet-stream&#39;,
&#39;exe&#39; => &#39;application/octet-stream&#39;,
&#39;class&#39; => &#39;application/octet-stream&#39;,
&#39;so&#39; => &#39;application/octet-stream&#39;,
&#39;dll&#39; => &#39;application/octet-stream&#39;,
&#39;oda&#39; => &#39;application/oda&#39;,
&#39;pdf&#39; => &#39;application/pdf&#39;,
&#39;ai&#39; => &#39;application/postscript&#39;,
&#39;eps&#39; => &#39;application/postscript&#39;,
&#39;ps&#39; => &#39;application/postscript&#39;,
&#39;smi&#39; => &#39;application/smil&#39;,
&#39;smil&#39; => &#39;application/smil&#39;,
&#39;mif&#39; => &#39;application/vnd.mif&#39;,
&#39;xls&#39; => &#39;application/vnd.ms-excel&#39;,
&#39;ppt&#39; => &#39;application/vnd.ms-powerpoint&#39;,
&#39;wbxml&#39; => &#39;application/vnd.wap.wbxml&#39;,
&#39;wmlc&#39; => &#39;application/vnd.wap.wmlc&#39;,
&#39;wmlsc&#39; => &#39;application/vnd.wap.wmlscriptc&#39;,
&#39;bcpio&#39; => &#39;application/x-bcpio&#39;,
&#39;vcd&#39; => &#39;application/x-cdlink&#39;,
&#39;pgn&#39; => &#39;application/x-chess-pgn&#39;,
&#39;cpio&#39; => &#39;application/x-cpio&#39;,
&#39;csh&#39; => &#39;application/x-csh&#39;,
&#39;dcr&#39; => &#39;application/x-director&#39;,
&#39;dir&#39; => &#39;application/x-director&#39;,
&#39;dxr&#39; => &#39;application/x-director&#39;,
&#39;dvi&#39; => &#39;application/x-dvi&#39;,
&#39;spl&#39; => &#39;application/x-futuresplash&#39;,
&#39;gtar&#39; => &#39;application/x-gtar&#39;,
&#39;hdf&#39; => &#39;application/x-hdf&#39;,
&#39;js&#39; => &#39;application/x-javascript&#39;,
&#39;skp&#39; => &#39;application/x-koan&#39;,
&#39;skd&#39; => &#39;application/x-koan&#39;,
&#39;skt&#39; => &#39;application/x-koan&#39;,
&#39;skm&#39; => &#39;application/x-koan&#39;,
&#39;latex&#39; => &#39;application/x-latex&#39;,
&#39;nc&#39; => &#39;application/x-netcdf&#39;,
&#39;cdf&#39; => &#39;application/x-netcdf&#39;,
&#39;sh&#39; => &#39;application/x-sh&#39;,
&#39;shar&#39; => &#39;application/x-shar&#39;,
&#39;swf&#39; => &#39;application/x-shockwave-flash&#39;,
&#39;sit&#39; => &#39;application/x-stuffit&#39;,
&#39;sv4cpio&#39; => &#39;application/x-sv4cpio&#39;,
&#39;sv4crc&#39; => &#39;application/x-sv4crc&#39;,
&#39;tar&#39; => &#39;application/x-tar&#39;,
&#39;tcl&#39; => &#39;application/x-tcl&#39;,
&#39;tex&#39; => &#39;application/x-tex&#39;,
&#39;texinfo&#39; => &#39;application/x-texinfo&#39;,
&#39;texi&#39; => &#39;application/x-texinfo&#39;,
&#39;t&#39; => &#39;application/x-troff&#39;,
&#39;tr&#39; => &#39;application/x-troff&#39;,
&#39;roff&#39; => &#39;application/x-troff&#39;,
&#39;man&#39; => &#39;application/x-troff-man&#39;,
&#39;me&#39; => &#39;application/x-troff-me&#39;,
&#39;ms&#39; => &#39;application/x-troff-ms&#39;,
&#39;ustar&#39; => &#39;application/x-ustar&#39;,
&#39;src&#39; => &#39;application/x-wais-source&#39;,
&#39;xhtml&#39; => &#39;application/xhtml+xml&#39;,
&#39;xht&#39; => &#39;application/xhtml+xml&#39;,
&#39;zip&#39; => &#39;application/zip&#39;,
&#39;au&#39; => &#39;audio/basic&#39;,
&#39;snd&#39; => &#39;audio/basic&#39;,
&#39;mid&#39; => &#39;audio/midi&#39;,
&#39;midi&#39; => &#39;audio/midi&#39;,
&#39;kar&#39; => &#39;audio/midi&#39;,
&#39;mpga&#39; => &#39;audio/mpeg&#39;,
&#39;mp2&#39; => &#39;audio/mpeg&#39;,
&#39;mp3&#39; => &#39;audio/mpeg&#39;,
&#39;aif&#39; => &#39;audio/x-aiff&#39;,
&#39;aiff&#39; => &#39;audio/x-aiff&#39;,
&#39;aifc&#39; => &#39;audio/x-aiff&#39;,
&#39;m3u&#39; => &#39;audio/x-mpegurl&#39;,
&#39;ram&#39; => &#39;audio/x-pn-realaudio&#39;,
&#39;rm&#39; => &#39;audio/x-pn-realaudio&#39;,
&#39;rpm&#39; => &#39;audio/x-pn-realaudio-plugin&#39;,
&#39;ra&#39; => &#39;audio/x-realaudio&#39;,
&#39;wav&#39; => &#39;audio/x-wav&#39;,
&#39;pdb&#39; => &#39;chemical/x-pdb&#39;,
&#39;xyz&#39; => &#39;chemical/x-xyz&#39;,
&#39;bmp&#39; => &#39;image/bmp&#39;,
&#39;gif&#39; => &#39;image/gif&#39;,
&#39;ief&#39; => &#39;image/ief&#39;,
&#39;jpeg&#39; => &#39;image/jpeg&#39;,
&#39;jpg&#39; => &#39;image/jpeg&#39;,
&#39;jpe&#39; => &#39;image/jpeg&#39;,
&#39;png&#39; => &#39;image/png&#39;,
&#39;tiff&#39; => &#39;image/tiff&#39;,
&#39;tif&#39; => &#39;image/tiff&#39;,
&#39;djvu&#39; => &#39;image/vnd.djvu&#39;,
&#39;djv&#39; => &#39;image/vnd.djvu&#39;,
&#39;wbmp&#39; => &#39;image/vnd.wap.wbmp&#39;,
&#39;ras&#39; => &#39;image/x-cmu-raster&#39;,
&#39;pnm&#39; => &#39;image/x-portable-anymap&#39;,
&#39;pbm&#39; => &#39;image/x-portable-bitmap&#39;,
&#39;pgm&#39; => &#39;image/x-portable-graymap&#39;,
&#39;ppm&#39; => &#39;image/x-portable-pixmap&#39;,
&#39;rgb&#39; => &#39;image/x-rgb&#39;,
&#39;xbm&#39; => &#39;image/x-xbitmap&#39;,
&#39;xpm&#39; => &#39;image/x-xpixmap&#39;,
&#39;xwd&#39; => &#39;image/x-xwindowdump&#39;,
&#39;igs&#39; => &#39;model/iges&#39;,
&#39;iges&#39; => &#39;model/iges&#39;,
&#39;msh&#39; => &#39;model/mesh&#39;,
&#39;mesh&#39; => &#39;model/mesh&#39;,
&#39;silo&#39; => &#39;model/mesh&#39;,
&#39;wrl&#39; => &#39;model/vrml&#39;,
&#39;vrml&#39; => &#39;model/vrml&#39;,
&#39;css&#39; => &#39;text/css&#39;,
&#39;html&#39; => &#39;text/html&#39;,
&#39;htm&#39; => &#39;text/html&#39;,
&#39;asc&#39; => &#39;text/plain&#39;,
&#39;txt&#39; => &#39;text/plain&#39;,
&#39;rtx&#39; => &#39;text/richtext&#39;,
&#39;rtf&#39; => &#39;text/rtf&#39;,
&#39;sgml&#39; => &#39;text/sgml&#39;,
&#39;sgm&#39; => &#39;text/sgml&#39;,
&#39;tsv&#39; => &#39;text/tab-separated-values&#39;,
&#39;wml&#39; => &#39;text/vnd.wap.wml&#39;,
&#39;wmls&#39; => &#39;text/vnd.wap.wmlscript&#39;,
&#39;etx&#39; => &#39;text/x-setext&#39;,
&#39;xsl&#39; => &#39;text/xml&#39;,
&#39;xml&#39; => &#39;text/xml&#39;,
&#39;mpeg&#39; => &#39;video/mpeg&#39;,
&#39;mpg&#39; => &#39;video/mpeg&#39;,
&#39;mpe&#39; => &#39;video/mpeg&#39;,
&#39;qt&#39; => &#39;video/quicktime&#39;,
&#39;mov&#39; => &#39;video/quicktime&#39;,
&#39;mxu&#39; => &#39;video/vnd.mpegurl&#39;,
&#39;avi&#39; => &#39;video/x-msvideo&#39;,
&#39;movie&#39; => &#39;video/x-sgi-movie&#39;,
&#39;ice&#39; => &#39;x-conference/x-cooltalk&#39;,
);
?>

#推薦學習:《PHP影片教學

以上是php中xls匯出亂碼怎麼辦的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn