user2473301 user2473301 - 5 years ago 105
PHP Question

Copy HTML code into text file

I got banned and can no longer ask questions. In hopes to rectify this, I'm editing my most down-voted threads with this block of text. My intention was never to clog Stackoverflow with dumb questions or to leech off the community, but I did at some point. I've realized my damage from reading this helpful thread How to Ask Questions the Smart Way. Now I'm hoping for forgiveness from the community for my unintentional damage. Thank you

My company uses an invoice software I've made. It's a simple page that copies input from fields, checkboxes and some dynamic table with Javascript into a new page with A4 CSS so it can be printed or sent via mail as PDF.

Now I have to start on the second feature: open an invoice. I have thought of one way I could make this.

When a new invoice is made and input is copied into the other page, to also copy all the HTML from the form in which all the inputs are into a text file with PHP - and later when a user "opens" an invoice, it just opens the file which just copies all the HTML code.

I don't know how to copy part of the code into a text file. So any help here?

If you also know an easier, better way please tell.

Thank you.

Answer Source

Use output buffering.

Before you render anything out to the browser do

ob_start();

after you do your rendering get the html content.

$html = ob_get_contents();

then to send it to the browser do.

ob_flush();

Then with the $html you can save to file, database or whatever works for your use case

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download