- BASICS
- Quotes
- Constants
- Control Structures
- Reference
- Number Systems
- VARIABLES
- Definition
- Variable Variable
- Exists
- Type Casting
- OPERATORS
- Aritmetic
- Bitwise
- String
- Comparison
- Logical
- FUNCTION
- Definition
- Anonymous
- Reference
- Variable Arguments
- ARRAY
- Basics
- Operations
- Create
- Search
- Modify
- Sort
- Storage
- STRING
- String Basics
- String Compare
- String Search
- String Replace
- String Format
- String Regexp
- String Parse
- Formating
- Json
- STREAMS
- File Open
- Read File
- Read Csv
- File Contents
- Context
-
Ob_start
- OOP
- Object Instantiation
- Class Constructor
- Interfaces, Abstract
- Resource Visibility
- Class Constants
- Namespaces
- HTTP
- Headers
- File Uploads
- Cookies
- Sessions
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.
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
**/
You have more control over the output.
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 ...
**/