473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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 14972

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: D. Alvarado | last post by:
Hello, I am trying to find the <TITLE> element of my document. Normally alert(document.title); works just fine, but when this statement is within a page that is a frame in a larger document,...
2
by: Rob | last post by:
Hello Group, I have trouble changing the <title> of my site, http://www.robcoers.nl I Changed the title in the frames rubriek.htm and body.htm but it keeps saying the old title, Rob Coers...
7
by: mitch gart | last post by:
Is it possible to insert newlines, or some other character, into <title> or <alt> to get the effect of a tooltip, where the page author controls the line breaks? If yes, could somebody send an...
1
by: mr_burns | last post by:
Hi there, I would like to a pages title (e.g. <title>this part please</title>) using javascript. How would this be done? I assume it could be done through the DOM model but I dont know too much...
5
by: Carlo Marchesoni | last post by:
Is it possible to change the document's title property from code behind (c#) ? I need to build a dynamic title at runtime.
1
by: Carlo Marchesoni | last post by:
Some days ago I asked this forum whether it is possible to set up the <title> from the code-behind. A couple of poeple helped me and in fact it is quite ease: a) change the HTML, e.g.: <title...
13
by: guitarromantic | last post by:
Hey everyone. I'm editing some stuff I did last summer, trying to bugfix and improve stuff. One improvement (or an oversight of the original design) is adding dynamic <title> tags to my pages....
15
by: Steve B | last post by:
Is there a way to manipulate the <TITLEin the csharp code?
5
by: dbuchanan | last post by:
How can a page title be supplied at runtime. It looks to me like it is hard coded, but there must be some way. <head runat="server"> <title>Training</title>
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.