Page 1 of 1

How to execute PHP code that's read in?

Posted: Wed Nov 24, 2004 9:14 am
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!

Posted: Wed Nov 24, 2004 9:24 am
by MarK (CZ)
You mean [php_man]require[/php_man] / [php_man]include[/php_man] commands?

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

Posted: Wed Nov 24, 2004 9:37 am
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.

Posted: Wed Nov 24, 2004 9:43 am
by phpScott
maybe something like http://uk.php.net/variables.variable might work?

Posted: Wed Nov 24, 2004 10:11 am
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).