|
Posted by Hilarion on 11/10/05 13:36
> If I've got one file called header.php that contains the following code ...
>
> <html>
> <head>
> <title><?php echo "$title_string";?></title>
You do not need quotes around variable. The instruction should
look like this:
echo $title_string;
or even:
echo htmlspecialchars( $title_string );
> </head>
>
>
> and I've got index.php that contains the following code ...
>
> <?php $title_string = "My Title String"; ?>
> <?php include "header.php"; ?>
You do not need to use two PHP sections. You can join the
code into one section for example like this (I used single
quotes because they do not evaluate special chars which
makes using "$" sign and quotes in those easier):
<?php
$title_string = 'My Title String';
include 'header.php';
?>
> Main body contents<br>
> </html>
>
> Why is the $title_string variable empty (or undefined) in header.php?
> Basically, my actual header.php is a lot bigger, and I want
> all my webpages to include this header, but specifying different options
> - ie. the title string, and a few others.
This example above should work (even with those quotes around variable
in the header file). Have you checked if this simple example works on your
PHP server? If not, then check it. If this one works, and your actual code
does not, then you have some error in the actual code. We'd have to see it
to tell what is wrong with it.
Hilarion
[Back to original message]
|