My code looks like:
index.php
:
<html>....
<title>My page</title>
....
<?php
switch ($_GET['id']){
case "tips":
include("tips.php");
$title = "Tips";
...
How do I get the title varible to the html title
tag?
All pages pass through index.php
.
Do your PHP before your HTML output.
<?php
switch ($_GET["id"]) {
case "tips":
$title = "Tips";
$page = "tips.php";
}
?>
<html>
<head>
<title><?php print $title; ?></title>
</head>
<body>
<?php include($page); ?>
</body>
</html>
< title > <?php echo $title; ?> < /title >
If you cannot use what Ahmet KAKICI suggests, add a script tag which sets document.title
<html>....
<title>My page</title>
....
<?php
switch ($_GET['id']){
case "tips":
include("tips.php");
$title = "Tips";
...
?>
<script>top.document.title="<?php=$title?>"</script>
My PHP is rusty, just wanted to suggest document.title
You can also do this with output buffering and a little string replacement.
<?php ob_start('ob_process'); ?>
<html>....
<title>{{{TITLE}}}</title>
....
<?php
switch ($_GET['id']){
case "tips":
include("tips.php");
$title = "Tips";
break;
}
function ob_process($buffer) {
global $title;
$buffer = str_replace('{{{TITLE}}}', $title, $buffer);
return $buffer;
}