How to execute PHP code that's read in?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
firemyst
Forum Newbie
Posts: 6
Joined: Sat Feb 01, 2003 5:33 pm

How to execute PHP code that's read in?

Post by firemyst »

Hi there,

We have a situation where we need to read a php file from another php file, and somehow get the php code within the file we've read to execute (basically, have variables replaced with their values) after we've read it.

Is there a way to do this?

If not, I'm sure we could probably do it via brute force... that is, search the string for all values like <?=$var1?> ... <?=$var2?> ... and replace them with the actual values. What would be the correct syntax for doing this?

Thanks!
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

You mean [php_man]require[/php_man] / [php_man]include[/php_man] commands?
firemyst
Forum Newbie
Posts: 6
Joined: Sat Feb 01, 2003 5:33 pm

Can't use require/include. Instead using "file"

Post by firemyst »

No. I mean actaully doing a "file" to read in the entire file. We don't want to use require/include, because these pages are executed separately most of the time (ie, http://www.whatever.com/file.php).

There are a few occassions the content of those pages are in an IFRAME, and to create a printer-friendly version, of the IFRAME's content along with the PARENT's content, we need to read the php file and do some special formatting.

The issue is how to replace variables in the file.php with the actual values as it's being parsed by the parent php script.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

maybe something like http://uk.php.net/variables.variable might work?
peni
Forum Commoner
Posts: 34
Joined: Thu Nov 18, 2004 1:15 pm

Post by peni »

though including would be a better solution, you can read the whole file in a string an use eval() on it.
(php.net/eval).
Post Reply