【发布时间】:2014-08-21 21:20:18
【问题描述】:
我有一个 html 表,我用复杂的逻辑填写 php。 有 4 个 foreach 循环来填充数据。
现在这工作正常,但通过循环我在我的元素中得到了一些空白。 浏览器可以正常显示,但是一要导出成pdf,就有点问题了。
任何人都知道如何消除这些空格。查看图片以获得更多说明:
这是我的变量的代码,我回显的变量没有任何空格。如果发出 echo "test"; 也会出现问题:
<div id="autoload-content">
<table class="tg" >
<thead>
<tr>
<th></th>
<th>Montag</th>
<th>Dienstag</th>
<th>Mittwoch</th>
<th>Donnerstag</th>
<th>Freitag</th>
</tr>
</thead>
<tbody>
<?php
$arrNoDoubleEntries = array();
$totalFactorMo = 0;
$stackIrregular = array();
//displays all the different presencetypes
foreach ($types as &$value) {
?>
<tr>
<td><?php echo ($value->Name);?></td>
<td>
<?php //all Monday Childs
if ($value->Name == "Total"){
echo ($totalFactorMo);
}else{
$childrenMonday = (Children::LoadPresence(1, $groupId));
foreach ($childrenMonday as &$child) {
foreach ($irregularPresence as &$irrugPrese){
if (($child->id == $irrugPrese->child_id) && ($monday >= $irrugPrese->datefrom) && ($monday <= $irrugPrese->dateto)){
if ($irrugPrese->away == 1 && ($value->id == $child->presencetype)){
echo("<s>".$child->fullName . " " . $child->factor."</s>");
echo "<br />";
array_push($stackIrregular, $child->id);
}
else{
if (($value->id == $irrugPrese->presencetype_id) AND (!(in_array($child->fullName + $irrugPrese->presencetype_id, $arrNoDoubleEntries)))){
echo("<u>".$child->fullName . " " . $child->factor."</u>");
echo "<br />";
array_push($arrNoDoubleEntries, $child->fullName + $irrugPrese->presencetype_id);
$totalFactorMo = $totalFactorMo + $child->factor;
}
}
}
}
if (!(in_array($child->id, $stackIrregular))) {
//prints the children which dont have some irregular Presences
if (!($child->presencetype == 1) && ($value->id == $child->presencetype)){
echo ($child->fullName . " " . $child->factor);
echo "<br />";
$totalFactorMo = $totalFactorMo + $child->factor;
}
}
}
}
?>
</td>
</tr>
</tbody>
</table>
</div>
【问题讨论】:
-
显示生成表格的代码……
-
为什么不尝试循环遍历表格单元格并使用javascript trim method?修剪空格
-
HTML 通常会忽略空格。你确定不加 或者像 这样的一些不可见的空间或将 CSS 设置为预先输入的空白处理
标签: php html html-table removing-whitespace