首页  >  文章  >  后端开发  >  php中xls导出乱码怎么办

php中xls导出乱码怎么办

藏色散人
藏色散人原创
2022-11-24 09:20:031754浏览

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