我正在循環一個數組並構建表。 HTML然後被髮送到DOMPDF。但是,如果HTML格式不正確,DOMPDF將不會創建PDF。我想這就是我的情況。這是我的循環:來自PHP循環的格式錯誤的HTML
<?php foreach($credits as $credit) : ?>
<?php if($credit['credit_type'] == "short") : ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:0px 0px 15px 0px;">
<tr>
<td><strong><?php echo $credit['category_title']; ?></strong></td>
</tr>
<tr>
<td><?php echo $credit['credit_heading']; ?></td>
</tr>
</table>
<?php endif; ?>
<?php if($credit['credit_type'] == "long") : ?>
<?php if($credit['category_title'] != $oldvalue) : ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:0px 0px 15px 0px;">
<tbody>
<?php endif; ?>
<tr>
<?php if($credit['category_title'] != $oldvalue) : ?>
<td width="25%"><strong><?php echo trim($credit['category_title']); ?></strong></td>
<td width="25%"><strong>Title</strong></td>
<td width="25%"><strong>Role</strong></td>
<td width="25%"><strong>Director</strong></td>
<?php endif; ?>
</tr>
<tr>
<td width="25%"><?php echo $credit['credit_heading'];?></td>
<td width="25%"><?php echo $credit['credit_title']; ?></td>
<td width="25%"><?php echo $credit['credit_role']; ?></td>
<td width="25%"><?php echo $credit['credit_director']; ?></td>
</tr>
<?php if($credit['category_title'] != $oldvalue) : ?>
</tbody>
</table>
<?php endif; ?>
<?php $oldvalue = $credit['category_title']; ?>
<?php endif; ?>
<?php endforeach; ?>
我不能爲我的生活工作出哪個標籤我不關閉。如果任何人都可以提供一些見解,那將是晶圓廠!
具體來說,循環創建顯示某些標題的行,然後在類別標題更改時再吐出更多行。
最簡單的方法就是用'ob_start()'和'ob_end()'獲得整個HTML,但爲什麼你的PDF庫不工作與「格式不正確的HTML」...? – evotopid 2012-01-06 17:06:00
那會怎麼樣?我將如何使用它? – Udders 2012-01-06 17:10:09
您使用的是哪個版本的dompdf? dompdf可以處理格式錯誤的HTML,儘管有一些格式化問題會導致渲染失敗。另外,如果HTML在結構上不正確,則渲染可能不符合您的期望。 – BrianS 2012-01-06 18:01:36