-
-
/** - * Export csv file, header function example
- * edit: bbs.it-home.org
- */
- header( "Cache-Control: public" );
- header( "Pragma: public" );
- header("Content-type:application/vnd.ms-excel");
- header("Content-Disposition:attachment;filename=txxx.csv");
- header('Content-Type:APPLICATION/OCTET-STREAM');
ob_start();
- $header_str = iconv("utf-8",'gbk',"信息id,标题,名称,电话,QQ,Email,内容,时间n");
- $file_str="";
-
- $mysqli= new mysqli('localhost','root','','test');
if (mysqli_connect_errno()) {
- printf("Connect failed: %sn", mysqli_connect_error());
- exit();
- }
- $sql='select * from messages';
- $mysqli->query("set names utf8 ;");
- $result=$mysqli->query($sql);
if($result){
- while ($row = mysqli_fetch_assoc($result)){
- $file_str.= $row['id'].','.$row['title'].','.$row['name'].','."'{$row['telephone']}'".','.$row['qq'].','.$row['email'].','.str_ireplace(',',',',$row['content']).','.$row['retime']."n";
- }
- }else{
- echo "nonono!!!";
- }
- $file_str= iconv("utf-8",'gbk',$file_str);
- ob_end_clean();
- echo $header_str;
- echo $file_str;
- ?>
-
复制代码
|