Jump to content

Archived

This topic is now archived and is closed to further replies.

johnnyk

require() with variables

Recommended Posts

Is it possible to do something like this:
require('whatever.inc?id=1');

Share this post


Link to post
Share on other sites
Unfortunatly not. Depending on what it is you wish to include, you could use an iframe, it's src attribute will accept files with variables appended to them.

Share this post


Link to post
Share on other sites
Is there a reason PHP doesn't let you do that. Seems like it would be pretty useful.

Share this post


Link to post
Share on other sites
These functions just make it easier to insert chunks of code into the code stream. Any variables that are defined before the included code are available to be used by the included code.

Ken

Share this post


Link to post
Share on other sites
But what if I want to modify what is included, for example:

require('whatever.php?id=1');

whatever.php
[code]
switch($_GET['id']){
case '1':
  echo 'echo this';
  break;
case '2':
  echo 'echo that';
  break;
}
[/code]

That seems useful. Is there any way to do something like that?

Share this post


Link to post
Share on other sites
use a function() {  } one one page.

then include("the page") then call that function() ok.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.