Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-11-2009
Member
 
Join Date: Mar 2009
Posts: 1,360
How to define a variable containing an include

Small question. Here is my current code:
Code:
$variable = include('file.php');
I would like the include to be contained in the variable and when I echo variable, it launches the include file. But the problem is that when I declare the include, it activates immediately. If I put quotation marks when I echo, the echo comes as text.

In short, if someone can help me, it would be great!

To quickly explain the use of: a config file switch based on the id I gave to each id, or have a variable content, or include a variable and this variable I echo in my template.
Reply With Quote
  #2  
Old 18-11-2009
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: How to define a variable containing an include

I see absolutely no application to what you want to do. But the closest match is to use the eval() instead of your echo:
PHP Code:
$variable "include('file.php')";
...
eval(
$variable); 
Reply With Quote
  #3  
Old 18-11-2009
Member
 
Join Date: Mar 2009
Posts: 1,360
Re: How to define a variable containing an include

I'll test it, but the application is simple.

Imagine a site without BDD window in your template you have a common area and sets a dynamic area for content. For each page or you have a short text or something more complex. And in the dynamic area of your template you have <?php echo $variable ?>

And you have a config file that switch according to the id of the page to define $variable or $variable = 'text', or $variable = include(file.php); if it ever needs to include an entire file.

Usually, I use a more complex dynamic include, but here I try to do something where you have to just edit your config file and at worst one or two external files for complex pages, to avoid having a different content page for each page.
Reply With Quote
  #4  
Old 18-11-2009
Member
 
Join Date: Nov 2008
Posts: 1,221
Re: How to define a variable containing an include

Instead of this:
PHP Code:
<?php echo $variable ?>
you put:
PHP Code:
<?php include("fichier.php" ); ?>
and even better, if you want to choose your content you put:
PHP Code:
$variable = "file.php"; // Here you choose the source
<?php include($variable); ?> // And you display it.
Reply With Quote
  #5  
Old 18-11-2009
Member
 
Join Date: Mar 2009
Posts: 1,360
Re: How to define a variable containing an include

Thank you for your reply but you do not answer any of my question. I know how to include a simple, this is not the issue. I want to have the choice between setting a variable with text or an include file, without using if, switch, etc. Your proposal will only work with a file, if $variable = "cuckoo"; it works obviously not.

My question is a variable that I defined as I (see above) and later with the function you want (echo, include, etc.), it displays either the include or the content, all without an if or a switch.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to define a variable containing an include"
Thread Thread Starter Forum Replies Last Post
How to define Union? seema_thk Software Development 5 15-12-2009 02:07 PM
Define the term- CLR for .NET Jesus2 Software Development 3 14-11-2009 09:10 PM
Runtime Error 91 : Object Variable or with block variable not set Ryan21 Software Development 2 28-08-2009 07:51 PM
What is Global Variable static? Declaring static variable instead of Global variable Reckon Software Development 3 25-04-2009 11:34 AM
Equivalent of #define in C# Luis234 Software Development 6 20-04-2009 11:56 PM


All times are GMT +5.5. The time now is 08:46 PM.