include('$file');

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
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

include('$file');

Post by m2babaey »

Hi
Can I do this:
$file="articledetails.php";
include('$file');
I really need it or something similar to make my pages more dynamic
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

Have you tried? :wink:
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

You can but use double quotes instead.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

or even better: no quotes at all.

Code: Select all

$file="articledetails.php";
include $file;
"$var" is a wide-spread nonsense.
User avatar
mabufo
Forum Commoner
Posts: 81
Joined: Thu Jul 10, 2003 11:11 pm
Location: Orland Park, IL
Contact:

Post by mabufo »

Code: Select all

include("nameoffile.php");
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Or just:

Code: Select all

include 'articledetails.php';
:wink:
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

or, to cover all the options, you could just choose to not include a file at all! ;)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

include is not a function, it is a language construct. As such, it doesn't require parentheses.

You never have to wrap a variable in quotes unless you are including plain, outputable text with it, and even then you can concatenate instead of parsing.

Try something before you ask if it can be done (really, in this case, how hard would that have been?).
Post Reply