dougu5847 2013-06-12 18:44
浏览 54
已采纳

将结果加载到缓冲区而不回显浏览器

How can I load loop results into a buffer using the PHP output control functions without echoing the results to the browser? In essence, what I'm trying to do is call results from the buffer as opposed to echoing my way through the loop "as it goes". Is it possible to do this? Any help appreciated. Thanks!

  • 写回答

2条回答 默认 最新

  • doushenyu2537 2013-06-12 18:48
    关注

    Use ob_get_contents to get the buffer contents without sending them.

    To clean out the buffer call ob_end_clean

    To do both in one step call ob_get_clean

    An example would be

    ob_start();
    foreach ($results as $result){
         include("tmplate/to/render/a/result.php");
    }
    $resultHTML = ob_get_clean();
    

    Then later.

    <div class='left-rail'><?= $resultHtml ?></div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line