very very newbie question > variables in include

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Patriot
Forum Commoner
Posts: 34
Joined: Tue Jun 18, 2002 1:36 pm

very very newbie question > variables in include

Post by Patriot »

how would you do this:

<? include ("$dir/$page"); ?>

would it be....
<? include ('$dir/$page'); ?>
or...
<? include ($dir/$page); ?>
or even...
<? include $dir/$page; ?>
?
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post by gnu2php »

The only one that works is the top one. The bottom three have errors.

This works:

Code: Select all

<? include ("$dir/$page"); ?>
Doesn't work. Tries to literally include $dir/$page (because of the single quotes):

Code: Select all

<? include ('$dir/$page'); ?>
Doesn't work, either. Division by 0 (since $page is 0 in numeric form):

Code: Select all

<? include ($dir/$page); ?>
Same problem, division by 0:

Code: Select all

<? include $dir/$page; ?>
Patriot
Forum Commoner
Posts: 34
Joined: Tue Jun 18, 2002 1:36 pm

Post by Patriot »

then could you do:
<? include ("dir/$page"); ?>
with the dir is not a variable, just the directory you want?
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post by gnu2php »

Yes. That works, too.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You don't need the parenthesis in an include statement, so

Code: Select all

<?php include "$dir/$file"; ?>
and

Code: Select all

<?php include $dir.'/'.$file; ?>
would both work as well.

Mac
Post Reply