I'm developing a php web application using Dreamweaver CS5. When I create a new page, Dreamweaver automatically adds the following code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
What I'm trying to do is to take this code and put it in a file, say 'head.php', and then I want to import this head.php file to all the pages I create using
<?php include("head.php"); ?>
If I do this, it means that I'm gonna have the same page title for every page because the code <title>Untitled Document</title>
is included in head.php.
So is there a way for me to send the page title via a variable from the new pages I create and then set it on the head.php document. So if I had a customer.php page, it would look something like this.
$pageTitle = "Customer List";
<?php include("head.php"); ?>
Then pass $pageTitle to the the head.php
Inside your header.php
function header($title)
{
echo '<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.$title.</title>
</head>';
}
then you include your head.php
< ?php include("head.php"); ?>
and finally, instead the < head >< /head > tags in your main file your call the function to create the title.
<?php header('This is my Awesome Page'); ?>
Or still
<?php
$pageTitle = "My Title";
header($pageTitle);
?>
This should work for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.