Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirecting output of a function...

Status
Not open for further replies.

kapok2002

Programmer
Aug 14, 2000
8
US
Here's my problem... I'm trying to assign the output of the include function to a variable. All I get is the status code if I go like: [tt]$var = include("filename")[/tt]. $var is 1 at this point. I'm thinking there's some operator that will redirect the output like: [tt]include("filename") ?? $var[/tt]. This should change standard output to $var instead of the html source, but what is the redirector (??)? Any help would be very appreciated. Thanks, Matt
 
Why dont you try doing something like:

Code:
$fd = fopen($filename,"r");
$contents = fread($fd,filesize($filename));
fclose($fd);

This opens the file, reads the contents of the file into variable $contents, then closes the file. After that you can do whatever you want with $contents.

If $filename is a file that contains PHP code, you can simply do eval($contents) to run the PHP code.
 
I tried that before, except for the eval($contents) part. Thanks for the help, Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top