PHP

SIMPLE EXAMPLES FOR PHP OUTPUT BUFFERING

START BUFFERING ob_start();

BUFFER START & FLUSH

01

HOLD "HELLO WORLD" IN BUFFER echo "hello"; echo " world";

RELEASE "HELLO WORLD" AS A SINGLE OUTPUT ob_flush();

HOLD "HELLO WORLD" IN BUFFER ob_start(); echo "hello"; echo " world";

BUFFER CLEAN

02

HOLD "FOO BAR" IN BUFFER echo "foo"; echo " bar";

CLEAR/RESET BUFFER ob_clean();

THIS WILL OUTPUT "FOO BAR" ob_flush()

HOLD "HELLO WORLD" IN BUFFER ob_start(); echo "hello"; echo " world";

BUFFER END CLEAN & FLUSH

03

THIS WILL EMPTY BUFFER + STOP STOP BUFFERING (NO OUTPUT) ob_end_clean();

THIS WILL OUTPUT "HELLO WORLD" + STOP BUFFERING ob_end_flush();

HOLD "HELLO WORLD" IN BUFFER ob_start(); echo "hello"; echo " world";

BUFFER GET CONTENT

04

"COPY" BUFFER TO VARIABLE & IMMEDIATELY OUTPUT $buff = ob_get_flush();

"COPY" BUFFER TO VARIABLE $buff = ob_get_contents();

"MOVE" BUFFER & EMPTY $buff = ob_get_clean();