Ob_start() function- Tutorials,Examples in Php5


ob_start Function is used to turn on output buffering.The PHP output buffering will save all the server outputs to a string variable.it  returns TRUE on success or FALSE on failure.
If you are using ob_start, then you should also use ob_end_flush  function for flushing the output buffer.

Ob_start() and ob_end_flush()  Example:

<?php
function changeColor($buffer)
{
  return (str_replace("Blue", "Red", $buffer));
}
//ob_start() function in PHP5
ob_start("changeColor");
?>
<html>
<tile>Ob_start() funtion Tutorials,Examples in Php5</title>
<body>
<span>Blue Car</span>
</body>
</html>
<?php
//ob_end_flush() function in PHP5
ob_end_flush();
?>
Output:
<html>
<tile>Ob_start() funtion Tutorials,Examples in Php5</title>
<body>
<span>Red Car</span>
</body>
</html>

Ob_start() and ob_get_clean()  Example:

<?php 
ob_start();
 ?>
<html>
<tile>Ob_start() funtion Tutorials,Examples in Php5</title>
<body>
<span>Blue Car</span>
</body>
</html>
<?php
 $code = ob_get_clean();
?>

Output:
<html>
<tile>Ob_start() funtion Tutorials,Examples in Php5</title>
<body>
<span>Blue Car</span>
</body>
</html>