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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Myth024
    New Member
    • Apr 2012
    • 3

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

    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.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    are you thinking hard? don't do it.
    just do simple
    your header.php
    Code:
    <title><?php echo $header;?></title>
    your anypage.php
    Code:
    $header="Any Page";
    include_once("header.php");
    ;)

    Comment

    • Myth024
      New Member
      • Apr 2012
      • 3

      #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.

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        is it that hard?
        Code:
        <?php 
        include("header.php");
        $Title="The Title of my page";
         ?>
        <header>
        <title><?php echo $Title;?></title>
        </header>
        <body>
        <center><?php echo $Title;?></center>
        </body>

        Comment

        • Myth024
          New Member
          • Apr 2012
          • 3

          #5
          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.

          Comment

          • johny10151981
            Top Contributor
            • Jan 2010
            • 1059

            #6
            We all had that stage of feeling dumb :) keep learning :)

            Comment

            Working...