我正在尝试使用php生成一个用word文件写的字母。 所以我尝试了以下代码。
mysql_connect("*****","****","****") or die("error");
mysql_select_db ("sampledb") OR DIE ("Unable to select db".mysql_error());
$query1 = "select * from table ";
$result1 = mysql_query($query1) or die (mysql_error());
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=exports22.doc");
header("Content-Transfer-Encoding: binary");
$k = 0;
$csvHandler = fopen("php://output", 'w');
$cars1=array("<table style='width:900px;'>
<tr><td>To</td></tr>
<tr><td style='font-size:100%;font-weight:bold;'>The Manager,</td></tr>
<tr><td >xyz ltd</td></tr>
<tr><td >Dear Sir / Madam,</td></tr>
<tr><td > </td></tr>
<tr><td style='font-size:100%;font-weight:bold;'>Sub : sample subject</td></tr>
<tr><td > </td></tr>
</table>
<table style='width:900px;' border='1' cellspacing='0' cellpadding='0'>
<tr><th>SR. NO.</th><th>ITEM NAME</th><th>QUANTITY</th><th>AMOUNT(Rs.)</th></tr>
</table>
");
fputcsv($csvHandler, $cars1);
while ($rows = mysql_fetch_array($result1)) {
$k++;
$query11 = "select * from employee where itemId = '".$rows['itemId']."' ";
$result11 = mysql_query($query11) or die (mysql_error());
$rows1 = mysql_fetch_array($result11);
$ename = $rows1['itemName'];
$acno = $rows1['Number'];
$no = $rows1['total'];
$rws="<table style='width:900px;' border='1' cellspacing='0' cellpadding='0'>
<tr><td>$k</td><td>$ename</td><td>$acno</td><td>$no</td></tr>
</table>";
$cars=array($rws);
fputcsv($csvHandler, $cars);
}
但在每张桌子之后,它正在写" "
。如何删除这些不需要的字符?