Conversion tables A-K
  Conversion tables L-Z
  SPAM database query
  Reverse WHOIS utility
  North America area codes
  PHP Example forums

PHP example repository.

Back to examples
Using output buffers

Output buffering allows you to control how data is sent to the browser. It also allows you to capture data before it is sent. This functionality gives you the ability, for example, to create static versions of dynamic pages ( maybe to save on database access ) or to send a HTML page via email.

To use output buffers to save a page, you will need three functions:

ob_start: To begin capturing the output
ob_get_contents: To get the contents in a variable
ob_end_flush: To send the data to the browser

The example below is a very simple use. Remember, you can put the functions in the middle of your PHP scripts to capture all or part of your output.

<b>Thanks for your order the details are as follows:</b>

// Start to capture the output


<tr><td>Order number</td><td>12321</td></tr>
<tr><td>Shipping date</td><td>22/11/1972</td></tr>

//    get the contents of the buffer into a variable

$content ob_get_contents();
// In this example send the content in an email - 
// in reality this is not a very efficent way of 
// sending the email in the middle of the script,
// but it will work for this example

$HTML         $content;
$from         "";
$to           "";
$subject     "Order confirmation";


// flush the data to the browser


<b>To return to the order page click here</b>

// Example 

$HTML         "<b>This is a test</b>";
$from         "";
$to           "";
$subject     "I'm sending a test HTML email";

// SendHTMLemail from example library