Jump to content


Photo

require() with variables


  • Please log in to reply
6 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 03 July 2006 - 03:27 AM

Is it possible to do something like this:
require('whatever.inc?id=1');
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 03 July 2006 - 03:08 PM

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.

#3 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 03 July 2006 - 05:48 PM

Is there a reason PHP doesn't let you do that. Seems like it would be pretty useful.
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 03 July 2006 - 05:53 PM

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

#5 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 03 July 2006 - 06:05 PM

But what if I want to modify what is included, for example:

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

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

That seems useful. Is there any way to do something like that?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 03 July 2006 - 06:11 PM

use a function() {  } one one page.

then include("the page") then call that function() ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 03 July 2006 - 06:19 PM

What would the function do? Could you give some example code?
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users