A simple way for PHP to export Excel without using Plug-ins

Source: Internet
Author: User
Tags foreach urlencode

  This article mainly introduces a simple way for PHP to export Excel without using Plug-ins, first get an array of the data that needs to be exported, and the format of the array is below. Then you define the file name and the style of Excel you want to export, and the last is the loop array, which outputs the data

  Code as follows: $filename =date ("Y-year m-month D-Day"). " Data information statistics results. xls ";          //filename $ua = $_server["Http_user_agent"];  //Chinese filename is not garbled if (Preg_match ("/msie/", $ua)) {      $filename =urlencode ($filename);} else if (Preg_mat CH ("/firefox/", $ua)) {      $filename = $filename;} else {      $filename =urlencode ($filen AME);   Header ("Content-type:application/vnd.ms-excel"); Outputs an Excel header header ("Content-disposition:filename=". $filename);       $n = Iconv (' utf-8 ', ' GBK ', ' 11 '); Set Excel table Column $t = iconv (' utf-8 ', ' gbk ', ' 22 '); $k = Iconv (' utf-8 ', ' GBK ', ') ';  $s = iconv (' utf-8 ', ' GBK ', ' 44 '); $r = Iconv (' utf-8 ', ' GBK ', ' 55 '); $a = iconv (' utf-8 ', ' GBK ', ' 66 ');   echo "{$n}t"; echo "{$t}t"; echo "{$k}t"; echo "{$s}t"; echo "{$r}t"; echo "{$a}tn";   foreach ($a as $kk => $pp) {//For each column of data foreach ($pp [' child '] as $k => $p) {echo iconv ("Utf-8", "gbk// IGNORE ", $pp [' U ']." T "); Echo iconv ("Utf-8", "Gbk//ignore", $p [' U ']. " T "); EchoIconv ("Utf-8", "Gbk//ignore", $p [' s ']. " T "); Echo iconv ("Utf-8", "Gbk//ignore", $p [' t ']. " T "); Echo iconv ("Utf-8", "Gbk//ignore", $p [' C ']. " T "); Echo iconv ("Utf-8", "Gbk//ignore", $p [' t ']. " TN "); }       array format     code is as follows: Array (    [0] => Array         ([uni TID] => 1234 [u] => AAA [FID] => 1000 [shengid] => 1000 [shiid] => 0 [Xianid] => 0 [RID] => 2 [Orders ] => [Sys_createuid] => 1 [sys_createtime] => 1383556976 [Sys_updateuid] => 1 [sys_updatetime] => 138985 3763 [child] => Array ([0] => Array (    [Unitid] => 1035     [u] => bbb     [ FID] => 1000     [Shengid] => 1000     [shiid] => 0     [Xianid] => 0   &NB Sp [RID] => 2     [orders] =>     [Sys_createuid] => 1     [sys_createtime] => 1 383556976     [Sys_updateuid] => 1     [Sys_updatETime] => 1389853763     [funitname] =>      [s] => 6     [T] => 1   & nbsp [C] => 1     [T] => 2)            [4] => Array (    [u] => Total     [s] => 8     [T] => 1     [C] => 3     [T] => 3))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.