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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Standard output 1

Status
Not open for further replies.

Masali

Programmer
Joined
Jun 19, 2002
Messages
143
Location
SE
Hi,

I have a script that reads in html-templates, and i want some keywords in the template to be changed into the output of another script. But if I use require() to include the script, the printout to the web browser will be instant, so I would like to redirect the standard output to a variable instead, so I can replace the keywords with the variable and later print it all out to the browser.

Please help, need it urgently!

Best regards

Masali
 
I want to run a php-script (1) within another script (2), and i want the output from the script no. 1 sent to a variable.

I was thinking that i could use

require "script1.php";

but first redirect the stdout to a variable instead of the browser window. Or do you have another idea of making this happen?
 
There's a couple of things you could try.

Since most of the newer PHP installations come with a stand-alone executable version of the interpreter, you could invoke the other script as an external application. You'd execute "/path/to/php scriptname.php".

You could also use output buffering.

You could modify the included script's code to be included in a function that will either return the text or print it depending on an input parameter.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I tried output buffering and that worked perfect! Thanks!

Code:
ob_start();
include "script.php";
$ret_str = ob_get_contents(); 
ob_end_clean();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top