Re: creating HTML page on-the-fly
| From: | Daniel Gustafsson | Date: | Tue, 04 Jul 2000 12:22:55 +0000 |
| Subject: | Re: creating HTML page on-the-fly | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-4730@lists.php.net to get a copy of this message | ||
At 05:11 AM 7/4/00 -0700, you wrote:
>How do u generate an HTML file on-the-fly using PHP?
>I'm making a greeting cards site and i'm storing
>values in sessions. I want to generate a page
>automatically when the user hits the submit button
>which will contain his choice of the card elements
>which have been stored in session variables. Also, at
>the same time a link to the page will be sent by
>email.
I'm not sure exactly what you mean, since the basic purpose of PHP is
generating HTML on the fly ;)
But I'm guessing what you are trying to do is to output everything into a
static file. I myself had been pondering about this until I saw a posting
to this list some time ago.
If you're using PHP4 you can utilize the output buffering. Turning the
output-buffering on (using ob_start), outputting everything like you would
normally do, and then storing the output in a variable (using
ob_get_contents) and outputting it to a file =)
---8<---
<?
ob_start();
?>
<html>
<head><title>Cool Card</title></head>
<body>
To: <?=$receiver?><br>
<img src='<?=$cardimage?>'><br>
<?
// yada, yada....
?>
</body>
</html>
<?
$data = ob_get_contents();
ob_end_clean();
// ... write $data to a file
?>
---8<---
This should probably do the trick, you might want to perform a flush()
before the ob_start() if you have output buffering enabled by default.
This is _really_ a handy feature of PHP4, saves you alot of keyboard
bashing =)