FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Includes and Variables?





Marston
I was just wondering if anyone knows how to create a PHP include, but with variables in the brackets, like so:
Code:
<?
$variable = '/usr/bin/';
include ($variable 'blah/asdfg.php');
?>

Obviously, the above example doesnt work, but does anyone know how to make it work?

Thanks. Wink
raver
include is for INCLUDING other php pages of code . For example you could have:

<?php
$variable = "anything";
?>//save this as var.php

and..

<?php
include ('var.php');
?>//save this with any name you would like
The second page now includes everything that is in var.php


You can find more about the include function in the manual at http://www.php.net/function.include
Naif
I guess you want the $variable to hold the path for the file you want to include? You can use the concatenation operator, that is '.' to do that

Code:

<?
$variable = '/usr/bin/';
include ($variable . 'blah/asdfg.php');
?>


I hope thats what you were trying to do.
dandelion
Naif wrote:
I guess you want the $variable to hold the path for the file you want to include? You can use the concatenation operator, that is '.' to do that

Code:

<?
$variable = '/usr/bin/';
include ($variable . 'blah/asdfg.php');
?>


I hope thats what you were trying to do.


There is a very similar, but a bit more readable solution (please note on double quotes and omitted brackets).
Code:
<?
$variable = '/usr/bin';
include "$variable/blah/asdfg.php";
?>
Related topics
php includes
Hacker-proof site without php?
How to create a dynamic PHP website.
Do we support php include and/or SSI?
php + forms + variables
Server Load
You're invited!!!!
Putting something on every page...
Variaveis pre-definidas[php]
Is this code safe, or not?
form mail problems (quality help=frih$)
PHP mailing script
Urls into variables
PHP Includes Problem
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.