How can output buffering be used to manipulate PHP code output from a file?
Output buffering in PHP can be used to capture the output generated by PHP code before it is sent to the browser. This allows developers to manipulate the output, such as modifying or filtering content, before it is displayed to the user. By using functions like ob_start() and ob_get_clean(), developers can buffer the output, manipulate it as needed, and then send the modified output to the browser.
<?php
ob_start();
// PHP code generating output
echo "Hello, World!";
// Get the buffered output and manipulate it
$output = ob_get_clean();
$output = str_replace("World", "PHP", $output);
// Send the modified output to the browser
echo $output;
?>