How can output buffering with ob_start() be used to prevent header modification errors in PHP?

Output buffering with ob_start() can be used to prevent header modification errors in PHP by capturing the output before it is sent to the browser. This allows you to modify headers or send cookies even after content has been sent. By using ob_start() at the beginning of your script, you can ensure that any header modifications or output changes can be made without causing errors.

<?php
ob_start();

// Your PHP code here

// Modify headers or send cookies
header('Content-Type: text/html');

ob_end_flush();
?>