Php 具有一个头文件的多个页面标题
我有一个文件的标题,这是包括在我的所有其他网页。我想知道我怎么能在同一个页眉上有不同的页面标题。我正在使用PHP和MySql。谢谢 将标题存储在变量中,例如Php 具有一个头文件的多个页面标题,php,html,css,header,include,Php,Html,Css,Header,Include,我有一个文件的标题,这是包括在我的所有其他网页。我想知道我怎么能在同一个页眉上有不同的页面标题。我正在使用PHP和MySql。谢谢 将标题存储在变量中,例如 $title = 'Main title'; if($page == 'this page has a different title') { $title = 'A different title'; } include 'header.php'; 在header.php集合中 <head> <title>
$title = 'Main title';
if($page == 'this page has a different title') {
$title = 'A different title';
}
include 'header.php';
在header.php集合中
<head>
<title><?php echo $title; ?></title>
...
...
在每个特定页面上,添加$pgName='page Title'代码>以设置每页的标题。然后,在该代码之后,include()
将标题作为正常内容。在头文件中,将其添加到
标记中:
<title><?php if(isset($pgName) && is_string($pgName)){echo $pgName;}else{echo 'Default title';} ?></title>
从include中取出title标签并将其放在页面中,这似乎迫使您采取变通办法