dragon87836215 2014-01-23 01:48
浏览 11

PHP - 使用include,我可以在页面中的不同div上执行吗?

I have a small problem, and I'll try to break it down into a smaller one so I can explain it properly.

I'm working on a web application and I have a couple of divs, such as this:

<div class="1">
//search bar
</div>

<div class="2">
include_once 'actioncontroller.php';
</div>

<div class="3">

</div>

In the actioncontroller.php I'm having an action controller which decides what action to take depending on what's pressed on the page. I've put it in the second div because ultimately that's where I want to print everything.

My question is, is there any way that I can use the code from the second div in the first one, without it printing it there? Basically I want the search bar from div one to do/print the same thing as the one in div 2 does, but I know(think) that PHP can't see code above the include_once, and if I include the actioncontroller.php in the first div it will print it there, instead of printing it in the second one, as I want.

Hope I was clear enough, it's not a problem of coding, it's just a matter of how can I read the script in the first div and then run it in the second one...

Thanks in advance

  • 写回答

2条回答 默认 最新

  • dongshi1934 2014-01-23 01:55
    关注

    This code takes the output of actioncontroller.php and saves it into a variable, which can be echo'd multiple times.

    <?php
    ob_start();
    include_once 'actioncontroller.php';
    $output = ob_get_contents();
    ob_end_clean();
    ?>
    
    <div class="1">
        <?php echo $output; ?>
    </div>
    
    <div class="2">
        <?php echo $output; ?>
    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题