You are here: Re: Very newbie question (including other php files) « PHP SQL « IT news, forums, messages
Re: Very newbie question (including other php files)

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация