473,226 Members | 1,706 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,226 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 14888

"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>
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.