Ob_start() Function -Tutorials and Examples in Php5
Posted by Raj
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>
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>
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
and header,
buffer size,
example,
not working,
Ob_start() in PHP,
PHP,
PHP interview questions and answers,
tutorials,
worpress
.You can leave a response, or trackback from your own site.