PDA

View Full Version : is it possible to have a variable inside the include() of php



laine
July 22nd, 2001, 08:24
i'd like to ask is it possible to have a varibable inside the include()

for example

$url="a.txt";

include('$url');

... i've tried and... it doesn't work

for example i have 2 variables
$chapter=1 // what chapter
$page=1 //what page in the chapter

i'd like to then include the relavant txt file... in the document
the url of the file is like

$chapter/$page.txt
but i have no idea how to include that ...

sorry :rolleyes: but i am a beginner to php, please help :) thanks

gyrbo
July 22nd, 2001, 11:21
use include($var); or include("$var");. If you use signle quotes, PHP doesn't interprent it as code, just plain text.

laine
July 22nd, 2001, 23:06
thx, i've got it now ^_^

niv
July 22nd, 2001, 23:33
also, if you use double quotes:



<?php
$php = "foo";
include ("$php/$php.inc");
?>

it's just like echo("");

gyrbo
July 23rd, 2001, 05:52
Yep:


<?php
$var = "Hello";
echo '$var';
echo "$var";
echo $var;
?>

Gives as output:

$varHelloHello

Weapon
July 23rd, 2001, 06:12
damn'it all these coding is giving me the headaches!!!!:p :mad: :confused: :( :o