如何摆脱Csv文件中不需要的Html和Css标签?

时间:2015-08-05 10:23:52

标签: php csv

我编写了一个代码,将所有表数据输出到csv文件中。但是在输出文件中会显示表格的标题,其余的是html和css标签,我不想在那个输出中输入。我写的代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"                             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php

//Connecting to database
include 'dbconn.php';
// create a file pointer connected to the output stream
$output=fopen('php://output', 'w');
$fileName = 'out.csv';
// $output = fopen('demosaved.csv', 'w');
ob_end_clean();
header('Content-Type: application/csv');
header('Content-Disposition: attachement; filename="' . $fileName . '"');

// output the column headings
fputcsv($output, array('id','first_name', 'last_name','cell_phone','email','insurance_carrier','date_created','date_last_modified','call_resolution','date_of_birth','address','city','state','zip','pain','scar','ed','herpers','shingles','metabolic','source_id'));


// fetch the data
// $rows=mysqli_query($connect,'SELECT id,first_name,last_name,cell_phone,date_created,date_modified,best_time_contact from      newform');
  $rows = mysqli_query($connect,"SELECT f.id,f.first_name,f.last_name,f.cell_phone,f.email,f.insurance_carrier,m.date_created,m.date_modified,m.call_resolution,m.d_o_b,m.address,m.city,m.state,m.zip,m.pain,m.scar,m.ed,m.herpers,m.shingles,m.metabolic, l.name FROM `newform` as f 
 left join medication as m on f.id = m.user_id
 left join livingdata as l on f.reference_id = l.id");

//die(print_r($rows));
// loop over the rows, outputting them
while ($row = mysqli_fetch_assoc($rows)) 
{
  fputcsv($output,$row);      
}
fclose($output);
//exit()
?>
<body>
<p>New Php </p>
</body>
</html>

0 个答案:

没有答案