Results 1 to 9 of 9

Thread: Using PHP to replace the <title> tag.

  1. #1
    Senior Member
    Join Date
    Aug 2004
    Location
    W Yorkshire
    Posts
    5,691
    Thanks
    85
    Thanked
    15 times in 13 posts
    • XA04's system
      • Motherboard:
      • MSI X570-A Pro
      • CPU:
      • AMD Ryzen 5 3600
      • Memory:
      • Corsair 2x 8gb DDR 4 3200
      • Storage:
      • 1TB Serpent M.2 SSD & 4TB HDD
      • Graphics card(s):
      • Palit RTX 2060
      • PSU:
      • Antec Truepower 650W
      • Case:
      • Fractcal Meshify C
      • Operating System:
      • Windows 10
      • Monitor(s):
      • iiyama 34" Curved UWQHD
      • Internet:
      • Virgin 100mb Fibre

    Using PHP to replace the <title> tag.

    Hi guys,
    I'm redesigning my website, but for the <title> tag inside the header is there a way i can change this so it is different using php? what i want to do is make php search the page for the <h1> tags, and the data inbetween will be entered into the title tag (i will be using the <h1> tag as the as the heading you see on the page, but i also want to use it for the title you see in the browser window).

    Sorry if thats confusing. Any help is apreicated, thanks.

  2. #2
    Agent of the System ikonia's Avatar
    Join Date
    May 2004
    Location
    South West UK (Bath)
    Posts
    3,736
    Thanks
    39
    Thanked
    68 times in 51 posts
    variable substicution

    set what ever you are going to make <h1> blah </h1> into a variable (I don't know how you planned to do this eg: if its coming from a database or a string search.

    then just print <title> $variable_from_h1 </title>
    It is Inevitable.....


  3. #3
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    you could get the page header and put it in.

    <title> $_GET['page'] </title>

    I've forgotten most my PHP but if you're using pages like that then you can retrieve the current page name, or just make a PHP file with a if else statement in it saying if($_GET['page'] == "News") { $variable = "News" } perhaps?

  4. #4
    Senior Member
    Join Date
    Aug 2004
    Location
    W Yorkshire
    Posts
    5,691
    Thanks
    85
    Thanked
    15 times in 13 posts
    • XA04's system
      • Motherboard:
      • MSI X570-A Pro
      • CPU:
      • AMD Ryzen 5 3600
      • Memory:
      • Corsair 2x 8gb DDR 4 3200
      • Storage:
      • 1TB Serpent M.2 SSD & 4TB HDD
      • Graphics card(s):
      • Palit RTX 2060
      • PSU:
      • Antec Truepower 650W
      • Case:
      • Fractcal Meshify C
      • Operating System:
      • Windows 10
      • Monitor(s):
      • iiyama 34" Curved UWQHD
      • Internet:
      • Virgin 100mb Fibre
    I'm not sure if were on the right tracks, let me just say i'm not all good with php .

    the <h1> tag will be in the same page as the <title> tag, (well it won't be, but i'm just saying it to make it simpler for you guys to answer).

    i know that inside the <title> tag there will be something like $_phpblah here, or something like that, but i'd like that to search through the page for the one and only <h1> tag, and inside of that tag to be copied into the <title> tag.
    So..
    the title tag will actually look like <title>$_php_stuff_here</title>

    and the <h1> tag lower down will be like: <h1>Information page</h1>

    So when the PHP page is launched, the title tag becomes "Information page".

    Thanks

  5. #5
    Agent of the System ikonia's Avatar
    Join Date
    May 2004
    Location
    South West UK (Bath)
    Posts
    3,736
    Thanks
    39
    Thanked
    68 times in 51 posts
    XA04,

    I learnt some basic (and I do stress basic) html for some web application testing.

    I managed to fetch content from a database, manipulate it and display it.
    I also managed to search flat text files for data and display it.

    This is the same principals - search the html/php page or variables and display it in the <title> tag.

    I've forgot most of the php as I'm not a web developer and I only learnt the basics. I used the SAMS php book, I suggest you purchase it and after a couple of chapters I'd guess you'd find this no problem
    It is Inevitable.....


  6. #6
    Bigger than Jesus Norky's Avatar
    Join Date
    Feb 2005
    Posts
    1,579
    Thanks
    1
    Thanked
    8 times in 8 posts
    The problem is that the <title> tag comes before the <h1> tag. You'd either need to set the h1 from the title (reverse it) or use JS to change the title once the page has been rendered.

  7. #7
    Senior Member
    Join Date
    Aug 2004
    Location
    W Yorkshire
    Posts
    5,691
    Thanks
    85
    Thanked
    15 times in 13 posts
    • XA04's system
      • Motherboard:
      • MSI X570-A Pro
      • CPU:
      • AMD Ryzen 5 3600
      • Memory:
      • Corsair 2x 8gb DDR 4 3200
      • Storage:
      • 1TB Serpent M.2 SSD & 4TB HDD
      • Graphics card(s):
      • Palit RTX 2060
      • PSU:
      • Antec Truepower 650W
      • Case:
      • Fractcal Meshify C
      • Operating System:
      • Windows 10
      • Monitor(s):
      • iiyama 34" Curved UWQHD
      • Internet:
      • Virgin 100mb Fibre
    Quote Originally Posted by ikonia
    XA04,

    I learnt some basic (and I do stress basic) html for some web application testing.

    I managed to fetch content from a database, manipulate it and display it.
    I also managed to search flat text files for data and display it.

    This is the same principals - search the html/php page or variables and display it in the <title> tag.

    I've forgot most of the php as I'm not a web developer and I only learnt the basics. I used the SAMS php book, I suggest you purchase it and after a couple of chapters I'd guess you'd find this no problem
    I know HTML pretty well, but i only know PHP very basicly. The most advance thing i've done is probably fetching something from mysql and putting it into a page.

  8. #8
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    PHP Code:
    <?php
    $title 
    'Some Information';
    echo 
    '<html><head><title>'.$title.'</title></head><body><h1>'.$title.'</h1>Rest of content</body></html>';

  9. #9
    Senior Member
    Join Date
    Aug 2004
    Location
    W Yorkshire
    Posts
    5,691
    Thanks
    85
    Thanked
    15 times in 13 posts
    • XA04's system
      • Motherboard:
      • MSI X570-A Pro
      • CPU:
      • AMD Ryzen 5 3600
      • Memory:
      • Corsair 2x 8gb DDR 4 3200
      • Storage:
      • 1TB Serpent M.2 SSD & 4TB HDD
      • Graphics card(s):
      • Palit RTX 2060
      • PSU:
      • Antec Truepower 650W
      • Case:
      • Fractcal Meshify C
      • Operating System:
      • Windows 10
      • Monitor(s):
      • iiyama 34" Curved UWQHD
      • Internet:
      • Virgin 100mb Fibre
    Quote Originally Posted by Iain
    PHP Code:
    <?php
    $title 
    'Some Information';
    echo 
    '<html><head><title>'.$title.'</title></head><body><h1>'.$title.'</h1>Rest of content</body></html>';
    That looks right, thanks.

    I'll play around with it a little, see if i can get it to how i want.

    -----------
    Edit:
    I'm using PHP to use includes on the page, and it coughs up errors on the include lines, any ideas?

    Thanks.
    ---------------------
    Edit2:
    Nvm, sorted, i just had to end the echo at the PHP includes part. and start it again after.
    Last edited by XA04; 16-05-2005 at 10:08 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP 4.3 vs 5 (which one should I start learning?)
    By malfunction in forum Software
    Replies: 8
    Last Post: 08-02-2005, 03:28 PM
  2. PHP Tutorials
    By gss03 in forum Software
    Replies: 4
    Last Post: 09-05-2004, 12:09 PM
  3. IMG tag change?
    By Allen in forum HEXUS Suggestions
    Replies: 14
    Last Post: 18-02-2004, 09:42 PM
  4. Replies: 1
    Last Post: 14-08-2003, 03:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •