simple variable php question

Status
Not open for further replies.

zebono2

Active Member
31
2010
0
10
im trying to call for a variable for part of a link

include ('$themedir; /index.php');

this is not working

the variable is $themedir = '/theme/default';

and is located in a diffent .php that had been included before
 
5 comments
1. can't call variable inside include
2. for your work, I suggest you do

if (index){
$themedir = '/theme/default';
}else{
$themedir = ' '/theme/default2';
}

load $themedir


hope this will help you guy
 
1. can't call variable inside include

Wrong, you can use variables inside a include statement

----------------------------
PHP:
include ('$themedir; /index.php');

Why is there a ; in the code and to use variables you need to use double quotes (")

PHP:
include ("$themedir/index.php");

Also, the themedir variable:
PHP:
$themedir = '/theme/default';

Whats the path from the script you are using?
use realpath() to check whether you are on the right directory or not

http://php.net/manual/en/function.realpath.php
 
I'm actually not a big fan of double quotes.

Personally I tend to always use single quotes when possible.
Here you have both methods:

PHP:
<?php
include($themedir . '/index.php'); // Notice the dot
?>

<?php
include("$themedir/index.php");
?>
 
Status
Not open for further replies.
Back
Top