【发布时间】:2016-09-19 07:26:20
【问题描述】:
我的 index.php 看起来像这样:
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title?></title>
</head>
<body>
<p>Hi, this is my homepage. I'll include some text below.</p>
<?php
include "myfile.php";
?>
</body>
</html>
"myfile.php" 例如包括以下内容:
<?php
$title = "Hi, I'm the title tag…";
?>
<p>Here's some content on the site I included!</p>
<p> 已输出,但 <title> 标记保持空白。
我如何才能从包含的站点获取$title,并在<body> 标记内显示包含的内容?
【问题讨论】:
-
你使用 echo $title 在屏幕上显示。
-
你想做什么。
include用于包含文件。让你的问题更清楚一点。 -
在使用
$title变量之前必须包含您的文件。 -
@Sasikumar,更新了我的问题。是的,但我需要将它包含在
<body>标签中,而不是在title标签之前。该怎么做? -
你可能可以......有点......通过对输出缓冲进行一些令人讨厌的处理,然后在将缓冲区释放到浏览器之前对其进行编辑......但这个问题的真正解决方案是更好地将您的数据与您的数据分开模板(MVC 模式值得一看)。