Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    73
    Thanks
    12
    Thanked 0 Times in 0 Posts

    echo title tag content - hopefully a simple question

    OK... I'm probably being really thick here....

    I have to change the title tag across all pages of the website, and while I'm at it, I figure it would be a grand idea to farm it out to an include as a large proportion of it is the same on each page.

    The code then, is thus...

    PHP 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" xml:lang="en" lang="en" >

    <head>

    <?php include_once("headertitle.php"); ?>

    <title><?php echo("$mainheadertitle"); ?> -- HOME</title>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    </head>
    ...and for the included file...

    PHP Code:
    <?php
    $mainheadertitle 
    "This is the title for the page";
    ?>
    ... but for some reason I don't seem to understand, the echo'd section of the title doesn't display in the title bar. Does anybody know why? or how to make it work? (trying to keep it simple by the way, evidently)
    Last edited by rhia; 05-28-2008 at 07:56 PM. Reason: php tags

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    PHP 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" xml:lang="en" lang="en" >

    <head>

    <title><?php include("headertitle.php"); ?> -- HOME</title>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    </head>

    included file ... it can be or doesn't need to be PHP.

    PHP Code:
    <?php
    echo "This is the title for the page";
    ?>

    EDIT ....

    The included file can do some logic to determine which title to insert ...

    PHP Code:
    <?php
    $url 
    substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);

    $title="This is the default title line";

    if(
    $url == "index.php"){
    $title="This is the main page";
    }

    if(
    $url == "contact.php"){
    $title="This is the contact page";
    }

    if(
    $url == "about.php"){
    $title="This is the about us page";
    }

    echo 
    $title;

    ?>
    Last edited by mlseim; 05-28-2008 at 08:41 PM.

  • Users who have thanked mlseim for this post:

    rhia (05-28-2008)

  • #3
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    try using require() instead of include_once(), since it will throw an error if the include isn't working.

    Make sure that you are including the right file. (Is it really supposed to be headerTitle.php or folder/headertitle.php etc)

    Let us know what happens..

    Edit: or do what mlseim said


    HTH
    Dan
    Last edited by whizard; 05-28-2008 at 08:24 PM. Reason: mlseim beat me to it
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • Users who have thanked whizard for this post:

    rhia (05-28-2008)

  • #4
    New Coder
    Join Date
    Aug 2005
    Posts
    73
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Wow- serious overthink on my part there perhaps. lol

    You are absolutely right... however, that yeilds another problem...

    The output from the code in the title bar then becomes "??php echo "This is the title for the page"; ?> -- HOME" (without the quotation marks... they're mine, because I'm, well, quoting.)

    Changing the included file to just contain the title text itself without any of the PHP yields "?his is the title for the page -- HOME" in the title bar. (first letter changed for a question mark)

    Which to my mind seems a bit bizarre... so problem mostly solved it seems, but not quite. If I was perplexed before, I'm even more so over the simpler version!

    (there were no errors yielded previously by the way, and the right filenames used - just the absense of the supposedly echoed variable content - I'd tried the whole lot; requires and includes)

    (edit: many thanks to mlseim for subsequent edits by the way - I'm sure the extra info could prove useful in future, pending a solutiong this little oddity of a problem.)
    Last edited by rhia; 05-28-2008 at 08:42 PM.

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Can you post what you have now (in the head section of the main file as well as the included file)

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I just tried it ... it works OK for me ...

    http://www.cgrelayforlife.com/title.php

    see the title line.

  • #7
    New Coder
    Join Date
    Aug 2005
    Posts
    73
    Thanks
    12
    Thanked 0 Times in 0 Posts
    okies...

    The full header (excuse the non-compliant uppercase tags)..

    PHP 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" xml:lang="en" lang="en" >

    <head>

    <title><?php include("headertitle.php"); ?> -- HOME</title>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <META NAME="KEYWORDS" CONTENT="keywords" />

    <META NAME="ROBOTS" CONTENT="ALL" />

    <link rel="stylesheet" href="style1.css" type="text/css" />

    </head>
    the include file :

    PHP Code:
    <?php
    echo "This is the title for the page";
    ?>
    Yields... "??php echo "This is the title for the page"; ?> -- HOME"

    This is the title for the page
    Yields... "?his is the title for the page -- HOME"

    Thanks.

    (edit: Further thought, not that I can think how it would be different, but I'm using a xampp lite package for localhost testing - could that be making a difference?)
    Last edited by rhia; 05-28-2008 at 08:49 PM.

  • #8
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    I assume that the main file is a .php file or other type of file which your server parses for php code.

    Also, this meta tag is weird:
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    it should be
    <meta http-equiv="content-type" content="text/html" charset="utf-8" />

    The only reason I bring that up is I'm just sitting here trying to find anything out of the ordinary in your code, anything that could possibly throw something out of whack.

    Dan
    Last edited by whizard; 05-28-2008 at 08:52 PM. Reason: icode tags
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #9
    New Coder
    Join Date
    Aug 2005
    Posts
    73
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Thanks for picking out that tag... completely missed that - for weeks!

    Sadly, no difference though. The main file is plain old HTML (well, XHTML)...

    parsed via .htaccess settings:
    RemoveHandler .html .htm

    AddType application/x-httpd-php .php .htm .html
    ... an include in the body containing pure HTML for the footer and a left hand menu at the end of the file works just fine.

    Is it just me, or is this php output in the title tag an example of something completely odd? lol
    Last edited by rhia; 05-28-2008 at 09:02 PM.

  • #10
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    maybe if you try using the print() command instead of echo()?

    :S

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #11
    New Coder
    Join Date
    Aug 2005
    Posts
    73
    Thanks
    12
    Thanked 0 Times in 0 Posts
    "??php print "This is the title for the page"; ?> -- HOME"

    It's just echoing (including) the text within the PHP include instead of parsing it... but whether there's mere text, or PHP code in headertitle.php, the result is whatever it contains, with it's first character changed for a question mark.

    <-- that's, erm, plain wierd.

  • #12
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Do you have somewhere you can upload it to for "live" testing? (Just to see if its your localhost causing the problem or if it is really an error in the coding)

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #13
    New Coder
    Join Date
    Aug 2005
    Posts
    73
    Thanks
    12
    Thanked 0 Times in 0 Posts
    That was my thought exactly, and so I did it just this moment...

    It's here

    Same problem! wow! (It'll be OK untill I change it back later lol - not like it has heavy traffic just at the moment)

  • #14
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    wow.. .that is weird. For the record, your meta tag is still missing a quote, right before utf-8.

    <meta http-equiv="content-type" content="text/html" charset=utf-8" />

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • Users who have thanked whizard for this post:

    rhia (05-28-2008)

  • #15
    New Coder
    Join Date
    Aug 2005
    Posts
    73
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Oh dear... part way there...

    Seems that there was an encoding issue - saved the php version of the include file as UTF-8 and it works (not sure how that changed), save for a single undisplayable character (a square in MSIE6) appearing at the beginning of it.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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