Re-engineering print()
| From: | Kristofer Widholm | Date: | Thu, 11 Jan 2001 04:36:53 +0000 |
| Subject: | Re-engineering print() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-33893@lists.php.net to get a copy of this message | ||
Hi, I'm involved in a conundrum that is a little difficult to explain with plain English. Perhaps some PHP code will help you understand what I am attempting:
#Option 1: code I wish worked
$s = include("phpcode.php");
#Option 2: also code I wish worked
$s = sprintf("%s", include('template.php'));
Basically, I'm wondering if there is a way to redirect print and echo output from PHP to a variable instead of directly to a browser or file stream. What I'm trying to do is create code that can generate an HTML page to a variable that I can manipulate and then later store in a database.
Obviously, the "real" way to do this is to not use print() statements at all, but simply build a variable as follows:
$output .= "<html> yadda yadda yadda";
$output .= sprintf("More html and function output %s", function());
until the $output contains the entire file.
The reason I don't want to do this is that it will require rewriting all my PHP file templates.
Also, I'm simply obsessed with the problem now. I even went as far as using eval() on the reading of an fopen(template.php) of the PHP template, but even then I couldn't assign the output to a variable.
Anyone want to kill themselves trying? My head hurts.
Sincerely,
Kristofer
--
http://www.brokenhill.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/~~~~~~~~~~~~~~~~~~~~~~~~
"The only real ideas are the ideas of the shipwrecked"
--Ortega y Gassett
~~~~~~~~~~~~~~~~~~~/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~