strange ob_start() behaviour - double output
Asked Answered
S

2

7

ob_start() doesn't seem to be stopping any output so when I flush the buffer it's doubling up

<?php
ob_start();
echo "Text..... <br />";
echo ob_get_flush();
?>

Outputs

Text..... 
Text..... 

But I was expecting

Text..... 

Any ideas ?

Thanks

Scotney answered 14/7, 2010 at 15:6 Comment(0)
R
14

Remove the echo on the last line.

ob_get_flush() implicitly prints the stored output and also returns it so you're printing it out twice.

You may have confused ob_get_flush() with ob_get_clean()

Ruder answered 14/7, 2010 at 15:9 Comment(0)
M
1

try:

<?php
ob_start();
echo "Text..... <br />";
ob_get_flush();
?>

from http://php.net/manual/en/function.ob-get-flush.php

Flush the output buffer, return it as a string and turn off output buffering

Flush the output means: it sends the output to the browser or the commandline. return the string means: it returns the string, so you can store the flushed string in a variable. And since you're echoing this string you get the output a second time.

Mitsukomitt answered 14/7, 2010 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.