On Fri, 17 Oct 2003 19:14:01 +0100, Geoff Berrow
<bl@ckdog.co.uk.the.cat> wrote:
[color=blue]
>I noticed that Message-ID: <c5b0pvsj4f8pm7imhgl49p8c2vpqekhi6n@4ax.com>
>from the wonderer contained the following:
>[color=green]
>>Thanks Geoff. I'm not sure though if I understand this.
>>
>>I currently have the header information, including title, in
>>PageStart.php.
>>
>>Are you saying to incorporate the header function into the
>>PageStart.php code, or make the function a separate file, or put the
>>function into any php file that would need it? Should I remove the
>>title declaration from PageStart.php altogether?
>>
>>I'm not sure how this would work:[/color]
>
>First of all let me apologise. The function cannot be called header()
>because that already exists in PHP (duh!) So call it head()[color=green]
>>
>> <?require_once('PageStart.php');
>> $title="My new Page";
>> header($title);
>> ?>
>>
>> or for the default
>>
>> <?require_once('PageStart.php');
>> header($title);
>>
>>Since PageStart.php already has <title> in it, wouldn't the subsequent
>>header($title) function either be ignored or cause a problem?[/color]
>
>The variable $title is what is passed to the function. If it isn't set
>then the default title is used. Here is my (corrected) code:
>
>PageStart.php (it's actually the full page here, but could just be the
>header naturally)
>
><?php
>function head($title){
> if(!$title){
> $title="Default page title";
> }
>?>
><html>
> <head>
> <title><?php print $title; ?></title>
>
> </head>
> <body>
> hello world
> </body>
> </html>
>
><?php } ?>
>
>And pages that use it
>p1.php
>
><?require_once('PageStart.php');
>head("My new Page");
>?>
>
>p2.php
>
><?require_once('PageStart.php');
>head($title);
>?>
>
>p3.php
><?require_once('PageStart.php');
>$title="something";
>head($title);
>?>
>
>It all works. I even tried
>
>p4.php
>
><?require_once('PageStart.php');
>$title="something";
>head(5+7/3);
>?>
>
>:-)
>
>See:
>
www.ckdog.co.uk/php/test[/color]
Okay, I reread your post and I went to the /php/test url above. So I
see that it works. But in trying to implement it, I'm failing. Maybe
if I could see the source of your pX.php and PageStart.php files?
Here is the start of my PageStart.php file (note that I changed the
name of your function head() to make_title() just so as not to confuse
the function head() with the <head> tag):
<?php
function make_title($title)
{
if(!$title)
{
$title="Page Default Title";
}
?>
<?php } ?>
<html>
<head>
<title><?php print $title; ?></title>
<?require_once('styles/BlueAndGold.css')?>
</head>
Now here is the first line of my index.php page:
<?require_once('PageStart1017.php', $title='My Web Site: Main
Page')?>
That line triggers a parse error. Since PageStart.php is included in
virtually every page on the web site, I don't know how to "let it
know" what page title is being used.
I appreciate your help on this. I am a php novice (obviously!) and
much of what I do consists of copying stuff I understand, then
gradually modifying it to suit my needs, with frequent visits to
php.net to check what I'm doing.