Page 1 of 1

very very newbie question > variables in include

Posted: Sat Jul 13, 2002 5:38 pm
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; ?>
?

Posted: Sat Jul 13, 2002 5:59 pm
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; ?>

Posted: Sat Jul 13, 2002 7:14 pm
by Patriot
then could you do:
<? include ("dir/$page"); ?>
with the dir is not a variable, just the directory you want?

Posted: Sat Jul 13, 2002 7:45 pm
by gnu2php
Yes. That works, too.

Posted: Mon Jul 15, 2002 1:48 am
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