What is the significance of the BOM-Byte in PHP and how does it affect the parsing of XML files?

The BOM-Byte (Byte Order Mark) is a special character that can be present at the beginning of a file to indicate its encoding. However, when parsing XML files with PHP, the BOM-Byte can cause issues such as "XML declaration not at the beginning of input". To solve this issue, you can remove the BOM-Byte from the XML file before parsing it.

$xml = file_get_contents('file.xml');
if (substr($xml, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) {
    $xml = substr($xml, 3);
}

$doc = new DOMDocument();
$doc->loadXML($xml);