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"
<?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
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
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
Last edited by whizard; 05-28-2008 at 08:24 PM..
Reason: mlseim beat me to it
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.)
Can you post what you have now (in the head section of the main file as well as the included file)
Dan
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
Yields... "??php echo "This is the title for the page"; ?> -- HOME"
Quote:
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?)
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
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
Last edited by whizard; 05-28-2008 at 08:52 PM..
Reason: icode tags
maybe if you try using the print() command instead of echo()?
:S
Dan
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
"??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.
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
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
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.