如果文件包含在页面的开头,我如何在页面上的特定位置回显包含文件的内容?
plugin.php:
<?php $txt = 'HELLO WORLD';?>
<div id="pl">
... some stuff.. <?php echo $text; ?>
</div>
main.php:
<?php
include 'plugin.php';
?>
<body>
<div>SOME TEXT BEFORE THE OUTPUT...</div>
<div><?php //content of included file goes here ?></div>
</body>
答案 0 :(得分:1)
<?php
$text = include 'plugin.php';
?>
<body>
<div>SOME TEXT BEFORE THE OUTPUT...</div>
<div><?php echo $text;//content of included file goes here ?></div>
</body>
您可以将包含文件的上下文存储在变量中。试试这个例子。
答案 1 :(得分:1)
你可以简单地做
<body>
<div>SOME TEXT BEFORE THE OUTPUT...</div>
<div><?php include 'plugin.php'; ?></div>
</body>
希望它有所帮助:)
答案 2 :(得分:1)
ob_start();
include($path);
return ob_get_clean();
这是有帮助的。