ob_get_contents
Description
The ob_get_contents of Output Control for PHP return the contents of the output buffer.
Syntax
ob_get_contents(): string|false
Return
This will return the contents of the output buffer or false, if output buffering isn't active.
Examples
1 · return
<?
ob_start();
echo "output";
$return = ob_get_contents();
echo PHP_EOL . "return: $return";
output return: output
2 · output · ob_end_clean
<?
ob_start();
echo "output1";
$return1 = ob_get_contents();
echo "output2";
$return2 = ob_get_contents();
ob_end_clean();
echo PHP_EOL . "return1: $return1" . PHP_EOL . "return2: $return2";
return1: output1 return2: output1output2
3 · output · ob_end_flush
<?
ob_start();
echo "output1";
$return1 = ob_get_contents();
echo "output2";
$return2 = ob_get_contents();
ob_end_flush();
echo PHP_EOL . "return1: $return1" . PHP_EOL . "return2: $return2";
output1output2 return1: output1 return2: output1output2