ob_start();
echo "Hello, World!";
$output = ob_get_contents();
ob_end_clean();
echo $output;
ob_start(function($buffer) {
file_put_contents('output.txt', $buffer);
});
echo "Hello, World!";
ob_end_flush();
function get_output() {
ob_start();
echo "Hello, World!";
$output = ob_get_contents();
ob_end_clean();
return $output;
}
$result = get_output();
echo $result;