Home > php教程 > php手册 > 导出csv

导出csv

WBOY
Release: 2016-06-07 11:37:27
Original
1114 people have browsed it

导出csv
<?php <br /> # TODO 增加内存限制值<br> ini_set('memory_limit', '2048m');<br> /**<br>  * 导入CSV<br>  * @param array $aData<br>  * @param array $aTitle<br>  * @param string $sFileName<br>  * @return boolean<br>  */<br> /*<br>     #TODO case:<br>     $aData = array(<br>         array('id'=>1,'name'=>'名称1'),<br>         array('id'=>2,'name'=>'名称2'),<br>         array('id'=>3,'name'=>'名称3'),<br>     );<br>     $aTitle = array(<br>         array('id','标记'),<br>         array('name','名称'),<br>     );<br>     exportCSV($aData, $aTitle);<br> */<br> function exportCSV($aData = [], $aTitle = [], $sFileName=false)<br> {<br>     if (!is_array($aData) || !is_array($aTitle))<br>         return false;<br> <br>     if (empty($aData) || empty($aTitle))<br>         return false;<br> <br>     $sFileName = $sFileName ? mb_convert_encoding($sFileName, "GB2312", "UTF-8, GB2312") . ".csv": date("_YmdHis") . ".csv";<br>     <br>     header('Content-Type: text/csv; CHARSET=gb2312');<br>     header('Content-Disposition: attachment; filename=' . $sFileName);<br> <br>     $output = fopen('php://output', 'w');<br>     <br>     for ($i=0;$i<count></count>         for($j=0;$j<count></count>             $aList[$i][$j] = mb_convert_encoding($aData[$i][$aTitle[$j][0]], "GB2312", "UTF-8, GB2312");<br>         }<br>     }<br>     for ($i=0;$i<count></count>         $aTitle[$i] = mb_convert_encoding($aTitle[$i][1], "GB2312", "UTF-8, GB2312");<br>     }<br> <br>     fputcsv($output, $aTitle);<br>     <br>     foreach ($aList as $key) {<br>         fputcsv($output, $key);<br>     }<br>     return true;<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template