How can PHP handle errors or unexpected behavior when sending headers to the browser?

When sending headers to the browser in PHP, errors or unexpected behavior can occur if headers are sent after output has already been sent to the browser. To handle this issue, you can use the `headers_sent()` function to check if headers have already been sent before attempting to send new headers. If headers have already been sent, you can use `header_remove()` to remove any previously sent headers before sending new ones.

if (headers_sent()) {
    header_remove(); // Remove any previously sent headers
}

// Send new headers
header('Content-Type: text/html');