PROGRAMMING

MINTE9
REMEMBERS




Last update:   11-08-2021

Ob_start()

It opens a buffer where the output is stored. Every time you do an echo, the output is added to that buffer. When you call ob_flush() the output is sent to the browser.
 RunCode
function callback($buffer) {
    return str_replace("apples", "bananas", $buffer);
}

ob_start("callback"); // Look Here

?>
    My string with apples and oranges.
<?php

ob_end_flush();

/**
    My string with bananas and oranges
**/
... 5 lines
˄˄˄
You have more control over the output.
 RunCode
ob_start();

$header = "UnitTests - %s <hr>";

echo "My tests passed ... <br>";
$passed = true;

echo "My tests 2 failed ... <br>";
$passed = false;

$output = ob_get_contents();
ob_end_clean();

$header = sprintf($header, $passed ? "Passed" : "Failed"); // Look Here
echo $header . $output;

/**
    UnitTests - Failed
    My tests passed ...
    My tests 2 failed ...
**/
... 9 lines
˄˄˄

Questions    
43. Object instantiation
42 . Ob_start
Last update:   11-08-2021

        A B C D E F
🔔
1/1