php include is this possible

Status
Not open for further replies.

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
is this possible the below code
PHP:
<?
$abc="somepage.php";
include('$abc');
?>

when i run the above script it says $abc doesnt exist ...
iam makin such a include coz the value of $abc keeps on changing
 

Penguin129

New Member
Messages
68
Reaction score
0
Points
0
Well, if you place a variable directly in a string, the text itself is part of the string and not the value of the variable. If you want to put a variable in a string you can do it via many methods such as using the {} things around the variable inside the string, or like so:
PHP:
$string = "text" . $variable . "more text";
But for the sake for simplicity, in the code you posted, you can remove the quotes around $abc.
 

Xemnas

New Member
Messages
812
Reaction score
0
Points
0
You need to use double quotes (i.e. ") instead of single quotes in your include(), or remove the quotes altogether. Single quotes parse literally (i.e. variables return as their name, not their value), while no quotes and double quotes parse variables as their value.

So, change your include() to one of the following:
PHP:
include("$abc");
include($abc);
 

Momiji

New Member
Messages
59
Reaction score
0
Points
0
when you are including a variable you do not need the " or the ' that should work.
 

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
thnks guys u made my work a hell lot easier
coz i was not able to include i had to use a long 12 line function to do it
 

Momiji

New Member
Messages
59
Reaction score
0
Points
0
lol its alright I was just thinking also that you could use

PHP:
<?
$abc = "somepage.php";
include $abc;
?>
 
Status
Not open for further replies.
Top