Results 1 to 5 of 5

Thread: How to define a variable containing an include

  1. #1
    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.

  2. #2
    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); 

  3. #3
    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.

  4. #4
    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.

  5. #5
    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.

Similar Threads

  1. How to define Union?
    By seema_thk in forum Software Development
    Replies: 5
    Last Post: 15-12-2009, 02:07 PM
  2. Define the term- CLR for .NET
    By Jesus2 in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 09:10 PM
  3. Replies: 2
    Last Post: 28-08-2009, 07:51 PM
  4. Replies: 3
    Last Post: 25-04-2009, 11:34 AM
  5. Equivalent of #define in C#
    By Luis234 in forum Software Development
    Replies: 6
    Last Post: 20-04-2009, 11:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,914,372.52199 seconds with 16 queries