Forum Moderators: coopster

Message Too Old, No Replies

how to make a web page title with php using variables or functions

php variables and funtions to make a title automatically from the topic

         

chikooo

5:10 pm on Feb 15, 2009 (gmt 0)

10+ Year Member



how do i auto create a web page title it has to be created from the web page topic. i want the web page topic to displayed as the web page title. i dont want to have to be writing all the title for all of the pages so i though that maybe if i put some kind of variable or function on the topic it and then the function or variable print it as the title

sorry for the bad explanation

rob7591

6:03 pm on Feb 15, 2009 (gmt 0)

10+ Year Member



If you have the variable at hand, you just need to have this in your <head>:

<title><?=$title?></title>

Where $title is the variable holding the title of your webpage. It's pretty self explanatory, echoing a variable in the title is just like echoing a variable anywhere else on a web page.

chikooo

1:29 am on Feb 16, 2009 (gmt 0)

10+ Year Member



when i put the code you said the web page doesnt load because of an error
"Parse error: syntax error, unexpected '=' in /index/source/modules/php/head_tag.php on line 2" this is what i see it seems that is the equal sign that causes this. and if i take the equal sign out the page loads as usual but i dont get what i want the variable to do.
i would like to add that the content that goes between the <head>and </head> section i have a include file using php so i just update the include file and there is where i put the title

rob7591

1:40 am on Feb 16, 2009 (gmt 0)

10+ Year Member



Oh well your version of PHP might not support <?= syntax.

Use <title><? echo $title; ?></title>

chikooo

7:51 pm on Feb 16, 2009 (gmt 0)

10+ Year Member



didnt work neither. <?php $title = "Animals"; print $title; ?> this is the variable that i have as the topic of the page ok but i dont see in the title

coopster

12:22 pm on Feb 17, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, use the full syntax of
<?php
as it is most portable and always available. Do you have that code between the HTML title tags as suggested?

trigoon

2:16 pm on Feb 17, 2009 (gmt 0)

10+ Year Member



<?php $title = "Animals"; print $title; ?> should work just fine, if it doesn't then my best guess is that your host doesnt support PHP. Either that or you have some error in your script which is being suppressed by error_reporting(0) and causing you not to see anything.

The only other cause I can think of is that you didn't put <?php $title = "Animals"; print $title; ?> between the title tags. <title><?php $title = "Animals"; print $title; ?></title>

chikooo

1:21 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



my host suppport php just fine because i have other php scripts running just finee. but look i want to put this on the body <?php $title = "Animals"; print $title; ?> somewhere like part of the topic title but i want it to be displayed on the body. it only displays "animals" just like i want. but now i want to be able to display animals in the title <title> <?php print $title; ?></title> like this. so i wont have to write "animals" myself on the title. do you get me

chikooo

1:25 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



<head>
<title <?php print $title; ?></title>
</head>
<body>
<center><?php $title = "Animals"; print $title; ?></center>
</body>

i want something like this to display what i put on the body on the title as well.
maybe it helps

chikooo

1:38 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



the last code i posted is wrong
<head>
<title> <?php print $title; ?></title>
</head>
<body>
<center><?php $title = "Animals"; print $title; ?></center>
</body>

but didnt work either
so i tried this

<head>
<title>dhdhd</title>
</head>
<body>
<center><?php $title = "Animals"; print $title; ?></center>
<?php echo $title; ?>
</body>

i put anything on the title right. and i use echo on the body and it actually did what i wanted it print animals/
but what i think that might be the proble is that

i am doing this

<head>
<?php include("http://www.mysite.com/index/source/modules/php/head_tag.php") ?>
</head>
<body>
<center><?php $title = "Animals"; print $title; ?></center>
</body>

on the head file that is this one [mysite.com...]

is where i put the title
so maybe that is why i cannot echo the $title variable on another web page using include.
any suggestions