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元