【发布时间】:2018-04-22 03:24:02
【问题描述】:
我正在建立一个小型个人网站。为了使事情保持小规模并避免一遍又一遍地写东西,我有一个header.php 文件,每个子目录index.php 文件include 的。所以,每个index.php 文件都有这些行:
$title = someTitleVariableOrMethod;
include('/var/testsite/docroot/header.php');
在我的 header.php 文件中,我有这些行(我知道我可能会改进格式,但首先我想让标题正常工作)。
<html>
<head>
<?php
if (isset($title)) {
echo '<title>' . $title . '</title>';
} else {
echo '<title>Sampletext</title>';
}
?>
<style>
//a bunch of irrelevant css
</style>
</head>
<body>
//this is the end of the header file, the rest is dealt with in the index.php file
但由于某种原因,标题的内容和我所有的 CSS 都显示在 <body> 的开头(我在浏览器中按 F12 时看到了这一点),而在 <head> 中根本没有显示任何内容。我只想将标题内容放在标题标签中。我该如何解决这个问题?
提前致谢。
【问题讨论】: