嗨〜我想知道是否有一种方法要求回声中的PHP文件

时间:2014-07-30 06:55:43

标签: php

我想知道是否有一种方法可以在这样的回声中要求另一个php文件:

<?php
        echo "
        <label>Post Notifications</label>
        <div>
        <?php require_once('libraries/notifications/post_notifications.php'); ?>
        </div>";
?>

I know the <?php require_once('libraries/notifications/post_notifications.php'); ?> isn't correct but just hope you can get the idea. Thank you!

1 个答案:

答案 0 :(得分:1)

使用ob_get_contents。这些标签之间的所有内容都存储在变量端清理。

ob_start();

include('libraries/notifications/post_notifications.php');

$output = ob_get_contents();

ob_end_clean();

所以看起来输出如下:

<?php
echo "
  <label>Post Notifications</label>
  <div>
    {$output}
  </div>
";
?>