OK, I've got a question here and I'm not entirely sure if it's possible (of course, everything's possible..just gotta know how to do it)
Here's the deal: I've got a PHP page that is basically a form processor. It processes a hefty chunk of data and then outputs it in a nicely laid out table. The administrator of the site then needs to get this data. Rather than trying to email all of the details (probably 50 numbers, at least...), I'd like to instead just generate an HTML file (filename based on server time, perhaps) and save it to the server. Then send a link to that static HTML file.
Here's a basic rundown.
PHP page processes data and outputs it to the screen.
PHP page generates invoice_98712347.html and saves it to the server.
PHP page sends an email to admin with a link to 98712347.html
98712347.html should be an EXACT copy of the data that was output to the screen. IE, I want the script to basically parse the HTML output of itself and then save that to a new filename.
Is this possible? IF so, please help me out (on a tight deadline)
PS - I know that I could just save all of the data in a database and retrieve it with something like invoice.php?invoiceid=1234, but I DO NOT want to go this route.
I don't know the $_POST variables you're using, so I can't put any form processing code in place, but here's the scaffolding for the rest:
// invoice ID in a variable, which I assume changes?
$invoice_id = '98712347';
// prolog first
$page = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
// now the page title
$page .= "
// now the rest; replace this with code to generate the table on the fly.
$page .= '<body>
// write out the page
$file = @fopen('invoice_' . $invoice_id . '.html','w');
if ($file !== false)
// could not open the file; handle the error however you want
Well, yeah, heredoc syntax is cleaner, and you can still embed variables in it and have them resolve (just have them filled in BEFORE you declare the string variable).
But if you're building something on the fly (for example, an indeterminate number of table rows), you'll need to first construct that part, assign it to a variable, and then have it appear in the heredoc string.
There is a way of trapping the entire output of a script to a variable. It's done via output buffering functions.
You can look those functions up at php.net, as I haven't got much time to explain them. Anyway, here goes:
ob_start(); // turn output buffering on
// do your form processing here
$content = ob_get_contents(); // the entire content is stored here, so now either write it to a file or output it to the user, it's up to you
I'm sorry for providing such a vague example, after I get some time I'll provide a better example unless you someone else helps you with that. Feel free to PM me if you don't find required solution soon enough. Good luck.
The PHP page is all about messy HTML. I don't use loops to construct the tables (actually..I don't think there are any loops on the entire page)....The data is calculated and output, not stored to variables, so assigning the page content to a variable would require me to go through all of the code and assign everything to variables to insert into the body variable....
Output buffering sounds like what would be best for me?? (
If it just saves the generated HTML code, I'll be happy.