The ob_start() function will turn output buffering on and used for output buffering so that the headers are buffered and not sent to the browser.


we have external file data.PHP we want to store in Buffer using ob_start() function and then get the buffer value via ob_get_contents(), You can use this as a variable and print or use as anywhere.

File structure

┣ data.php
┗ index.php


ob_start();  //turns on output buffering
include 'data.php';
$output = ob_get_contents();


<!DOCTYPE html>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="" rel="stylesheet">
                margin: 0;
                font-family: 'Roboto', sans-serif;
                font-size: 12px;

                max-width: 800px;
                margin: 10px auto;
                background: #fff;
                padding: 20px;

                text-align: center;
                line-height: 10px;

                text-align: center;
                width: 100%;

            table th{
                border-right: 1px solid #ccc;

            table td{
                border-right: 1px solid #ccc;
                padding: 20px 0px;

                background: #f1e9e9;
                padding: 7px;

        <div class="invoice-container">
            <div class="comp_addr">
                <h3>TAX INVOICE</h3>
                <div class="my-address">
                    <h1>Tech. Rudranshi Software Solution</h1>
                    <th>Bill To</th>
                    <th>Place of Supply</th>
                    <td>RK Electrical Works</td>
                    <td>A-240 Rajouri Garden,New Delhi</td>
                    <th>INVOICE No</th>
                    <th>Description of Goods</th>
                    <th>Taxable Value</th>

                    <td>LED LIGHTS</td>

                    <td>Tube LIGHTS</td>

                <tr style="text-align: right">

Some more buffering functions

ob_start();  // turns on output buffering
ob_clean();  // delete the contents of the buffer, but remains buffering active
ob_flush(); // send buffer output
$none = ob_get_contents();  // buffer content is now an empty string
ob_end_clean();  // turn off output buffering