Andrew
Andrew

Reputation: 148

php echo inside of include workaround?

The Question:

How do you include a page, who's location is based on a variable?


The Goal:

Set Variables (theme location) in a settings.php file...

Root index, should reflect the index depending on the settings.php variable


Thanks For The Help Guys!

-Andrew


<!----//settings.php//---->
<?php 
$siteurl = "http://www.example.com/"
$themefolder = "theme/"; 
$theme = "theme1/"
?>

<!----//index.php//---->
<?php include("settings.php"); ?>

//how do you $E = echo settings variables?
<?php include(" $E index.php"); ?>

Any ideas for a work around?


I want to achieve... include(" $E index.php"); ?> = http://www.example.com/theme/theme1/index.php

Upvotes: 1

Views: 2114

Answers (4)

Your Common Sense
Your Common Sense

Reputation: 157839

<?php include $_SERVER['DOCUMENT_ROOT'].'/'.$themefolder.$theme."index.php" ?>

Upvotes: 0

Adam Arold
Adam Arold

Reputation: 30528

So you basically want to include http://www.website.com/theme/theme1/index.php?

That is easy:

<?php
include($siteurl . $themefolder . $theme . "index.php");
?>

I think that it would be easier to think about this if we knew what do you want to achieve. Include different pages according to the url?

Upvotes: 2

Shane
Shane

Reputation: 2047

What you are trying to do is really supposed to be done with a database, not a PHP script.

Upvotes: 0

Rene Pot
Rene Pot

Reputation: 24815

When you include a file, you have access to all the variables in scope already, just like it is 1 big file. No need to do weird things there.

So if you have this in your settings.php:

$themefolder = "theme/"; 

Than you can echo it like this:

!----//index.php//---->
<?php 
include("settings.php");

//echo theme folder
echo $themefolder; // will display "theme/"

Upvotes: 0

Related Questions