生成PHP时出错


error generate PHP

这已经困扰我几个小时了。当我尝试生成pdf时,我得到了以下错误:1) 警告:第540行C:''examplep''htdocs''KPAPMS''PHP''lib''pdftable.PHP中的零除2) FPDF错误:一些数据已经输出,无法发送PDF文件

我只是使用现有的代码来生成pdf(fpdf)。

这是我的代码示例

<?php
$sql = "SELECT * from vesservice";
$res = mysql_query($sql);
$hdd= "<table width=100%>
<tr><th width=100><strong>Company</strong></th><th><strong>: Kuching Port Authority</strong></th><th></th>
<th>Date / Time: ".$date."</th></tr>
<tr><th width=100><strong>Title</strong></th><th><strong>: Water Supply for SCN</strong></th><th></th><th></th></tr>
<tr><th colspan=4><hr></th></tr>
<tr>
<th><strong>SCN</strong></th><th>:</th>
<th><strong>Berth Date</strong></th><th>:</th></tr>
<tr>
<th><strong>Debtor Code</strong></th><th>:</th>
<th><strong>Expected Depart Date / Time</strong></th><th>:</th></tr>
<tr>
<th></th><th></th>
<th><strong>Actual Depart Date / Time</strong></th><th>:</th></tr>
<tr><th colspan=4><hr></th></tr>
</table>";
$tables="<table width=100%>
<tr align=center>
<th>Service Reference</th>
<th>Service Code</th>
<th>Water Supply Reference</th>
<th>Water Supply Sequence</th>
<th>Tariff Code</th>
<th>Tariff Description</th>
<th>UOM</th>
<th>Service Date</th>
<th>Requested Time</th>
<th>Volume<br />(Tonne)</th>
<th>Service Date</th>
<th>Started Time</th>
<th>Volume<br />(Tonne)</th>
<th>Service Date</th>
<th>Ended Date</th>
<th>Duration</th></tr>";
while($rs=mysql_fetch_assoc($res))
{
$tables.= "<tr align=center>
<td>".$rs['serv_opt']."</td>
<td>".$rs['dt_code']."</td>
<td>".$rs['scn']."</td>
<td>".$rs['term_code']."</td>
<td>".$rs['serv_cat']."</td>
<td>".$rs['serv_code']."</td>
<td>".$rs['activ_cnt']."</td>
<td>".$rs['serv_date_req']."</td>
<td>".$rs['serv_shift_req']."</td>
<td>".$rs['serv_qty']."</td>
<td>".$rs['serv_ref']."</td>
<td>".$rs['res_serv_date']."</td>
<td>".$rs['res_serv_time']."</td>
<td>".$rs['new_serv_date']."</td>
<td>".$rs['new_serv_time']."</td>
<td>".$rs['new_serv_qty']."</td>
</tr>";
}
$tables.="</table>";
//echo $hdd.'<br />'.$tables;
$p = new PDFTable('L','mm','a4');//set page orientation P/L
$p->SetFont('Times','',10);
$p->headerTable=$hdd;
$p->AddPage();
$p->htmltable($tables);
//ob_end_clean();
$p->output("Water Supply.pdf",'I'); //D=download

当我取消ob_end_clean的注释时,它可以生成pdf输出,但只打印$tables,但不打印表头。请帮帮我,哪一部分我做错了。

您可以尝试插入ob_end_clean();在输出之前。示例

<?php
require('fpdf.php');
$pdf = new FPDF();
//your code for eneration of the pdf
ob_end_clean();
$pdf->Output();
?>

好的,如果您希望FPdf正常工作,那么除了FPdf生成的内容之外,根本不能有任何输出。您可以使用以下正则表达式来解决删除php文件末尾的所有新行字符的问题

''?>''n''z

更换为

''?''n

例如:

<?php
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Ok, OK
$pdf->Output();
?>

但这不起作用

<?php
echo "You don't sent  before output";
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'OK oK);
$pdf->Output();
?>