我正在设计这个网站,我使用php中的include()
函数来回声文本和其他页面。这里的事情是,我只是想要一个头文件和一个页脚文件,页脚文件,我已经得到了,但我希望头文件能够显示它的标题,元关键字和元描述(如果查看源)基于用户想要访问的页面。例如
URL 1: index.php将以这个作为标题
<title>This is the Home page</title>
<meta name="keyword" content="this, home, page" />
<meta name="description" content="welcome to home page" />
URL 2: about.php将以这个作为标题
<title>About us</title>
<meta name="keyword" content="about, us, page" />
<meta name="description" content="This website is about" />
我希望我正确地表达了这个问题。所以现在的事情是,如果用户去一个不同的页面说contact.php
标题应该动态地改变我写的关于联系我们的页面和元应该以及改变我所写的内容。所以谁能帮助这个问题,因为我想使用PHP数组,但我不知道如何构建代码。
如果你想让它是动态的,我建议你使用一个函数来代替。调用函数而不是使用include。如
function printHeader($title, $name, $content) {
echo "<title>{$title}</title>
<meta name='{$name[0]}' content='{$content[0]}' />
<meta name='{$name[1]}' content='{$content[1]}' />";
}
调用函数而不是使用include()
只需在调用include之前声明一个带有信息的变量。例如:
<?php
$title="Your title here";
include("header.inc.php");
...
然后,在头文件中:& lt; title> & lt; ?