I've been struggling with this problem and I can't figure out why is there a white space in the first line of the xml file.
I'm creating the XML as string, like so:
$xml = '<?xml version="1.0" encoding="utf-8" standalone="no" ?>';
$xml .= '<AuditFile xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.03_01">';
The following image represents the code above.
And then I save the file this way
$xml = new DOMDocument('1.0');
$xml->preserveWhiteSpace = FALSE;
$xml->formatOutput = TRUE;
$xml->loadXML($xmlString);
$xml->save('myfile.xml');
The problem now is that the file contains a space in the first line.
How can I remove it? I've tried without any success ltrim($xmlString);