Home > php教程 > php手册 > csv数据的导出

csv数据的导出

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 11:41:02
Original
1465 people have browsed it

csv数据的导出,平时使用Thinkphp处理数据,不过代码和以下的代码逻辑类似!不依赖任何第三方的类库
//数据处理<br> function exportData(){<br>     <br>     $result = mysql_query("select * from student");<br>     $str = "姓名,性别,年龄\n";<br>     $str = iconv('utf-8','gb2312',$str);<br>     while($row=mysql_fetch_array($result)){<br>         $name = iconv('utf-8','gb2312',$row['name']);<br>         $sex = iconv('utf-8','gb2312',$row['sex']);<br>         $str .= $name.",".$sex.",".$row['age']."\n";<br>     }<br>     $filename = date('Ymd').'.csv';<br>     export_csv($filename,$str);<br> }<br> <br> //输出<br> function export_csv($filename,$data) {<br>     header("Content-type:text/csv");<br>     header("Content-Disposition:attachment;filename=".$filename);<br>     header('Cache-Control:must-revalidate,post-check=0,pre-check=0');<br>     header('Expires:0');<br>     header('Pragma:public');<br>     echo $data;<br> }

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

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