What role does the BOM (Byte Order Mark) play in UTF-8 encoded PHP documents and potential header errors?

The BOM (Byte Order Mark) is a sequence of bytes at the beginning of a UTF-8 encoded file that indicates the byte order and encoding of the file. In PHP documents, the presence of a BOM can cause header errors when outputting content to the browser, as it may be interpreted as part of the output. To solve this issue, you can remove the BOM from the PHP file by saving it without the BOM or by using a text editor that allows you to remove the BOM.

// Remove BOM from UTF-8 encoded PHP file
ob_start();
include 'your_php_file.php';
$output = ob_get_clean();
echo $output;