Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-28-2008, 07:53 PM   PM User | #1
rhia
New Coder

 
Join Date: Aug 2005
Posts: 73
Thanks: 12
Thanked 0 Times in 0 Posts
rhia is an unknown quantity at this point
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
rhia is offline   Reply With Quote
Old 05-28-2008, 08:18 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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..
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
rhia (05-28-2008)
Old 05-28-2008, 08:23 PM   PM User | #3
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
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
whizard is offline   Reply With Quote
Users who have thanked whizard for this post:
rhia (05-28-2008)
Old 05-28-2008, 08:29 PM   PM User | #4
rhia
New Coder

 
Join Date: Aug 2005
Posts: 73
Thanks: 12
Thanked 0 Times in 0 Posts
rhia is an unknown quantity at this point
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..
rhia is offline   Reply With Quote
Old 05-28-2008, 08:38 PM   PM User | #5
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
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.
whizard is offline   Reply With Quote
Old 05-28-2008, 08:42 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I just tried it ... it works OK for me ...

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

see the title line.
mlseim is offline   Reply With Quote
Old 05-28-2008, 08:46 PM   PM User | #7
rhia
New Coder

 
Join Date: Aug 2005
Posts: 73
Thanks: 12
Thanked 0 Times in 0 Posts
rhia is an unknown quantity at this point
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"

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?)

Last edited by rhia; 05-28-2008 at 08:49 PM..
rhia is offline   Reply With Quote
Old 05-28-2008, 08:52 PM   PM User | #8
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
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
whizard is offline   Reply With Quote
Old 05-28-2008, 08:58 PM   PM User | #9
rhia
New Coder

 
Join Date: Aug 2005
Posts: 73
Thanks: 12
Thanked 0 Times in 0 Posts
rhia is an unknown quantity at this point
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:
Quote:
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..
rhia is offline   Reply With Quote
Old 05-28-2008, 09:00 PM   PM User | #10
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
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.
whizard is offline   Reply With Quote
Old 05-28-2008, 09:06 PM   PM User | #11
rhia
New Coder

 
Join Date: Aug 2005
Posts: 73
Thanks: 12
Thanked 0 Times in 0 Posts
rhia is an unknown quantity at this point
"??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.
rhia is offline   Reply With Quote
Old 05-28-2008, 09:07 PM   PM User | #12
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
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.
whizard is offline   Reply With Quote
Old 05-28-2008, 09:10 PM   PM User | #13
rhia
New Coder

 
Join Date: Aug 2005
Posts: 73
Thanks: 12
Thanked 0 Times in 0 Posts
rhia is an unknown quantity at this point
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)
rhia is offline   Reply With Quote
Old 05-28-2008, 09:12 PM   PM User | #14
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
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
__________________
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.
whizard is offline   Reply With Quote
Users who have thanked whizard for this post:
rhia (05-28-2008)
Old 05-28-2008, 09:19 PM   PM User | #15
rhia
New Coder

 
Join Date: Aug 2005
Posts: 73
Thanks: 12
Thanked 0 Times in 0 Posts
rhia is an unknown quantity at this point
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.
rhia is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:02 AM.


Advertisement
Log in to turn off these ads.