开发者

Page.Title equivalent in PHP

I want to change the title of my PHP pages dynamically but since the headers 开发者_如何学Pythonand footer sections are include files so I cannot use <title><?php echo $title;?></title> kind of solution.

I am wondering if there is any solution such as the one in Asp.NET Page.Title = "Some Title"; maybe like $page->set_title('Programmers Palace');

Many thanks...


Since the headers and footer sections are include files so I cannot use <title><?php echo $title;?></title> kind of solution.

You can. Just because the files are included doesn't mean you can't echo things there.

If you had a Page object...

index.php

<?php

$page = new Page('Programmers\' Palace');

include 'includes/header.php';

includes/header.php

<head>
  <title><?php echo $page->getTitle(); ?></title>
</head>


<?php

$title = 'My Page';

include 'header.php';

then in header.php:

<title><?php echo $title;?></title>

This works because file includes in php are treated as if they are "pasted in between there".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜