469,304 Members | 2,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

Page <title> from include variable?

IF I have something like this:

<title><?php print($pagetitle); ?></title>
<body>
<?php include("folders/my_include.php"); ?>
</body>
</html>

and my_include.php contains the value to the variable ($pagetitle). How do I
get the value before the code for the <title> is written. This is just a
basic example I used to try and put across my question, my site has a whole
bunch of includes dynamically generated from user input. I'd just like to
get the <title> to change according to a variable in the includes......but
Im stuck?

I should say also that all my includes have includes themselves, they
include a html template. So placing <?php include("folders/my_include.php");
?> before the title tag won't look very good :)

thanks

mark
Jul 17 '05 #1
13 14558

"mark" <dg*******@asdfasd.com> wrote in message
news:bs**********@news5.svr.pol.co.uk...
IF I have something like this:

<title><?php print($pagetitle); ?></title>
<body>
<?php include("folders/my_include.php"); ?>
</body>
</html>

and my_include.php contains the value to the variable ($pagetitle). How do I
get the value before the code for the <title> is written. This is just a
basic example I used to try and put across my question, my site has a whole
bunch of includes dynamically generated from user input. I'd just like to
get the <title> to change according to a variable in the includes......but
Im stuck?

I should say also that all my includes have includes themselves, they
include a html template. So placing <?php include("folders/my_include.php");
?> before the title tag won't look very good :)

thanks

mark

================================================== ==

....include a html template. So placing <?php
include("folders/my_include.php");
?> before the title tag won't look very good..

How do you mean, having an include before the title tag won't look very
good - The include would not appear in the client browser nor in the source
of the html that might be viewed from the client browser. If you have your
PHP server configured correctly, the PHP is parsed before it gets to the
client...

This means... you could have

<? include("folders/my_include.php");?>
<html>
<head>
<title><?php print($pagetitle); ?></title>
</head>

or

<? include("folders/my_include.php");?>
<html>
<head>
<title>
<? include("folders/my_include.php");
print($pagetitle); ?></title>
</head>
Both would give the exact same results - both should not echo any PHP to the
client web browser but instead just have whatever value you have assigned to
$pagetitle inbetween the <title> tags... thus, you already know the
solution - and what looks good is down to your own program flow as only
someone with developer access to your code will be able to view the PHP in
which case you should use plenty of white space and remark statements to
help you understand your program flow should you (or someone else) have to
return and edit the code in weeks or months time...

If I've misunderstood your question, then please make it clearer...
otherwise... Happy New Year,

laters
randell d.
Jul 17 '05 #2
its late and I'm tired so I may not be reading this properly but it
looks like what you need to do is call the include file before you set
the page title:

<?php
include("folders/my_include.php");
?>
<title><?php echo("$pagetitle");?></title>
..
..
..
..
..
Randell D. wrote:
"mark" <dg*******@asdfasd.com> wrote in message
news:bs**********@news5.svr.pol.co.uk...
IF I have something like this:

<title><?php print($pagetitle); ?></title>
<body>
<?php include("folders/my_include.php"); ?>
</body>
</html>

and my_include.php contains the value to the variable ($pagetitle). How do I
get the value before the code for the <title> is written. This is just a
basic example I used to try and put across my question, my site has a whole
bunch of includes dynamically generated from user input. I'd just like to
get the <title> to change according to a variable in the includes......but
Im stuck?

I should say also that all my includes have includes themselves, they
include a html template. So placing <?php include("folders/my_include.php");
?> before the title tag won't look very good :)

thanks

mark

================================================== ==

...include a html template. So placing <?php
include("folders/my_include.php");
?> before the title tag won't look very good..

How do you mean, having an include before the title tag won't look very
good - The include would not appear in the client browser nor in the source
of the html that might be viewed from the client browser. If you have your
PHP server configured correctly, the PHP is parsed before it gets to the
client...

This means... you could have

<? include("folders/my_include.php");?>
<html>
<head>
<title><?php print($pagetitle); ?></title>
</head>

or

<? include("folders/my_include.php");?>
<html>
<head>
<title>
<? include("folders/my_include.php");
print($pagetitle); ?></title>
</head>
Both would give the exact same results - both should not echo any PHP to the
client web browser but instead just have whatever value you have assigned to
$pagetitle inbetween the <title> tags... thus, you already know the
solution - and what looks good is down to your own program flow as only
someone with developer access to your code will be able to view the PHP in
which case you should use plenty of white space and remark statements to
help you understand your program flow should you (or someone else) have to
return and edit the code in weeks or months time...

If I've misunderstood your question, then please make it clearer...
otherwise... Happy New Year,

laters
randell d.

Jul 17 '05 #3

"Shay Hurley" <Sh*********@sanshay.com> wrote in message
news:bs************@ID-219240.news.uni-berlin.de...
its late and I'm tired so I may not be reading this properly but it
looks like what you need to do is call the include file before you set
the page title:

<?php
include("folders/my_include.php");
?>
<title><?php echo("$pagetitle");?></title>
..
..

I think you are right - I had taken that for granted and missed that error
in the original post...
Jul 17 '05 #4
http://gzen.myhq.info -- free online php tools
"mark" <dg*******@asdfasd.com> wrote in message
news:bs**********@news5.svr.pol.co.uk...
IF I have something like this:
and my_include.php contains the value to the variable ($pagetitle). How do I get the value before the code for the <title> is written. This is just a
basic example I used to try and put across my question, my site has a whole bunch of includes dynamically generated from user input. I'd just like to
get the <title> to change according to a variable in the includes......but
Im stuck?

Try this:
$incFile = "folders/my_include.php";
$arymeta = get_meta_tags($incFile);
$pagetitle = $arymeta['inctitle'];
<title><?php print($pagetitle); ?></title>
<body>
<?php include($incFile); ?>
</body>
</html>

and in your included pages, try something like:
<meta name="inctitle" content="My page include page title">
<?php
....
...
...
?>

Please no flames guys, this is just a simple fix, not a be all end all, I
know this is two file reads to the same file, however since you are going
load it anyways, it gets cached by the server as the last file read, so
reading it again imediately should cause no hard drive activity. And is
basicaly the same as reading it into memory and parsing it before using it,
becouse after all, cached files are loaded into memory.
--
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #5
Is the problem that calling "folders/my_include.php" at the top of the page
would result in the code being run and outputting page content in the
header?

You can always wrap your code (the stuff in up "my_include.php") in a couple
of functions and do something like this:

// ----------------------------

<?php include_once('folders/my_include.php'); ?>
<html>
<head>
<title><?php show_title(); ?></title>
</head>
<body>
<?php show_header(); ?>
<?php show_page(); ?>
<?php show_footer(); ?>
</body>
</html>

// ----------------------------

That is a better way to do things really.

Jamie Burns.
Jul 17 '05 #6

"Jamie Burns" <se*****@email.com> wrote in message
news:bs*******************@news.demon.co.uk...
Is the problem that calling "folders/my_include.php" at the top of the page would result in the code being run and outputting page content in the
header?
yes, because my_include.php contains:

include("template.html");

so whenever my_include is included, so is the HTML template.
You can always wrap your code (the stuff in up "my_include.php") in a couple of functions and do something like this:


I can edit my_include.php because I have about 1000 of them in different
folders.

thanks

mark
Jul 17 '05 #7
"Randell D." <re**********************@and.share.com> wrote in message
news:vtoIb.874648$6C4.339482@pd7tw1no...


If I've misunderstood your question, then please make it clearer...
otherwise... Happy New Year,


It's the fact that my includes all have an included HTML template. So
wherever they are included so it's the attatched HTML, hence the reason i'm
struggling.

cheers
mark
Jul 17 '05 #8
I can edit my_include.php because I have about 1000 of them in different
folders.

thanks

mark

ok, it looks like you have 1,000's of files that already have a $pagetitle =
"...." in them, and it is
not feasable to edit any of the files, is this correct? if so, I can provide
a solution. just need to be clear thats all.
--
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #9
"CountScubula" <me@scantek.hotmail.com> wrote in message
news:HM**************@newssvr29.news.prodigy.com.. .
ok, it looks like you have 1,000's of files that already have a $pagetitle = "...." in them, and it is
not feasable to edit any of the files, is this correct? if so, I can provide a solution. just need to be clear thats all.


yep, that's correct.

template.html contains:

<h1><?php print ($title); ?></h1><br><br> etc...

---------

my_includeX.php contains:

$title = "humpty dumpty";
include ("template.html");

--------

I need to get the variable $title into, the <title> tag of say "index.php"
without having the template.html printed out.

cheers

mark
Jul 17 '05 #10
> yep, that's correct.
template.html contains:
<h1><?php print ($title); ?></h1><br><br> etc... my_includeX.php contains:
$title = "humpty dumpty";
include ("template.html");

I need to get the variable $title into, the <title> tag of say "index.php"
without having the template.html printed out.

cheers
mark


Ok, here we go

<html>
<head>
<?php
ob_start();
ob_implicit_flush(0);
$incPage = "folders/my_include.php";
$pageContents = ob_get_contents();
ob_end_clean();
?>
<title><?php print($pagetitle); ?></title>
</head>
<body>
<?php print $pageContents; ?>
</body>
</html>
I have another solution too if that doesnt work
--
Mike Bradley
http://gzen.myhq.info -- free online php tools

Jul 17 '05 #11
oops, sorry, I messed up, it shoud read

<html>
<head>
<?php
ob_start();
ob_implicit_flush(0);
$incPage = "folders/my_include.php";
include($incPage);
$pageContents = ob_get_contents();
ob_end_clean();
?>
<title><?php print($pagetitle); ?></title>
</head>
<body>
<?php print $pageContents; ?>
</body>
</html>
With this, it is included, but all of its output is buffered, and stored in
a string.

--
Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #12
Easy. Just do this:

<html>
<body>
<?php include("folders/my_include.php"); ?>
</body>
<title><?php print($pagetitle); ?></title>
</html>

Most browsers will handle it as expected.

Uzytkownik "mark" <dg*******@asdfasd.com> napisal w wiadomosci
news:bs**********@news5.svr.pol.co.uk...
IF I have something like this:

<title><?php print($pagetitle); ?></title>
<body>
<?php include("folders/my_include.php"); ?>
</body>
</html>

and my_include.php contains the value to the variable ($pagetitle). How do I get the value before the code for the <title> is written. This is just a
basic example I used to try and put across my question, my site has a whole bunch of includes dynamically generated from user input. I'd just like to
get the <title> to change according to a variable in the includes......but
Im stuck?

I should say also that all my includes have includes themselves, they
include a html template. So placing <?php include("folders/my_include.php"); ?> before the title tag won't look very good :)

thanks

mark

Jul 17 '05 #13
Chung Leong wrote:
Easy. Just do this:

<html>
<body>
<?php include("folders/my_include.php"); ?>
</body>
<title><?php print($pagetitle); ?></title>
</html>

Most browsers will handle it as expected.


<html>
<head>
<?php
ob_start();
include 'folders/my_include.php';
$html_from_include = ob_get_contents();
ob_end_clean();
?>
<title><?php echo $pagetitle; ?></title>
</head>
<body>
<?php echo $html_from_include; ?>
</body>
</html>
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by D. Alvarado | last post: by
2 posts views Thread by Rob | last post: by
7 posts views Thread by mitch gart | last post: by
1 post views Thread by mr_burns | last post: by
5 posts views Thread by Carlo Marchesoni | last post: by
1 post views Thread by Carlo Marchesoni | last post: by
13 posts views Thread by guitarromantic | last post: by
15 posts views Thread by Steve B | last post: by
5 posts views Thread by dbuchanan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.