By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,066 Members | 1,841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,066 IT Pros & Developers. It's quick & easy.

Get Title of web page, print as text in body.

P: 3
Ok, so my index.php has a php include for a header.php file. This header file contains the meta tag information and the style sheet information. Each other .php file I have also has the php include for the header. What I would like to do is to be able to set the <title>Title of page</title> on each individual page, (do this manually) but have that same title echoed in text at the top of the page. Is there a way to use my header.php file to find the title on the page it's included on, then echo that title as text later in the document.
Apr 25 '12 #1

✓ answered by johny10151981

is it that hard?
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. include("header.php");
  3. $Title="The Title of my page";
  4.  ?>
  5. <header>
  6. <title><?php echo $Title;?></title>
  7. </header>
  8. <body>
  9. <center><?php echo $Title;?></center>
  10. </body>
  11.  

Share this Question
Share on Google+
5 Replies


100+
P: 1,059
are you thinking hard? don't do it.
just do simple
your header.php
Expand|Select|Wrap|Line Numbers
  1. <title><?php echo $header;?></title>
  2.  
your anypage.php
Expand|Select|Wrap|Line Numbers
  1. $header="Any Page";
  2. include_once("header.php");
  3.  
;)
Apr 25 '12 #2

P: 3
ok, so how does that work in this case..
<?php include("header.php") ?>
<header>
<title>The Title of my page</title>
</header>
<body>
<center>I want the title of my page printed here</center>
</body>

So I'm manually typing in the title for each page in the header information of each web page I create. Then I want to use that same title to echo the title at the top of the page as printed text. The header.php file is just basically code that I want on all of my pages. This way I don't have to keep adding it everytime I update or add another web page. Evenutally I will be using CSS to modify text on the pages so that's why I want to use my header.php to basically echo whatever I've set the title of the page to. I'm fairly new to php programming so thanks in advance for your patience.
Apr 27 '12 #3

100+
P: 1,059
is it that hard?
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. include("header.php");
  3. $Title="The Title of my page";
  4.  ?>
  5. <header>
  6. <title><?php echo $Title;?></title>
  7. </header>
  8. <body>
  9. <center><?php echo $Title;?></center>
  10. </body>
  11.  
Apr 27 '12 #4

P: 3
Well, I feel dumb. My brain must have been on vacation. I'm also learning PHP as I go too so I think I was being more complicated than I needed to be. Thanks.
Apr 30 '12 #5

100+
P: 1,059
We all had that stage of feeling dumb :) keep learning :)
Apr 30 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.