在 php 中暂停输出缓冲区
这是我的问题。我希望能够仅缓冲表的内容,而不缓冲表头。是否可以暂停 php 中的输出缓冲,以便我可以跳过表标题上的缓冲并在实际内容的开头再次恢复?
<?php ob_start(); ?>
<table>
<tr>
<th>Account</th>
<th>Quarter</th>
<th>Amount</th>
</tr>
<?php
foreach($tc_item as $v){
if($v->dbl_amt != 0){
?>
<tr>
<!-- Nature of Collection -->
<td id="nature"><?php echo $v->strDescription; ?></td>
<!-- Account Code -->
<td id="account"><?php echo $v->str_details; ?></td>
<!-- Amount -->
<td id="amount"><?php echo number_format($v->dbl_amt,2, '.', ''); ?></td>
</tr>
<?php } ?>
<?php } ?>
</table>
<?php
$_SESSION['or_details'] = ob_get_contents();
?>
Here's my problem. I want to be able to buffer only the contents of the tables but not the header. Is it possible to pause the output buffering in php so that I could skip the buffering on the table headers and resume again at the beginning of the actual content?
<?php ob_start(); ?>
<table>
<tr>
<th>Account</th>
<th>Quarter</th>
<th>Amount</th>
</tr>
<?php
foreach($tc_item as $v){
if($v->dbl_amt != 0){
?>
<tr>
<!-- Nature of Collection -->
<td id="nature"><?php echo $v->strDescription; ?></td>
<!-- Account Code -->
<td id="account"><?php echo $v->str_details; ?></td>
<!-- Amount -->
<td id="amount"><?php echo number_format($v->dbl_amt,2, '.', ''); ?></td>
</tr>
<?php } ?>
<?php } ?>
</table>
<?php
$_SESSION['or_details'] = ob_get_contents();
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你不想缓冲整个表,那么就不要缓冲它:
如果你想缓冲整个表,但想要单独缓冲表体,那么添加另一级缓冲:
或者,你可以刷新当前缓冲区无需创建新的。我不推荐这样做,因为它会使您的代码更难遵循。这也很愚蠢,因为如果您只是要刷新而不捕获字符串,那么您可能一开始就不缓冲:
If you don't want to buffer the whole table, then don't buffer it:
If you want to buffer the whole table, but want the table body separately, then add another level of buffering:
Alternatively, you can flush the current buffer without creating a new one. I don't recommend this because it makes your code harder to follow. It's also silly since if you're just going to flush without capturing the string, you might as well not buffer in the first place:
在 header 之后开始缓冲
Start buffering after the header