I am trying to generate an XML file in a PHP web application:
<?php
...
header('Content-Type: application/xml');
header('Content-Disposition: attachment; filename=test.xml');
echo "<?xml version=\"1.0\"?>\r\n" .
...
Bizarrely, when using my servers (PHP Version 5.3.8/Apache 2.2.17 and PHP Version 5.3.10-1/Apache 2.2.22 respectively) a line feed (hex 0a
) character is inserted in the beginning of the output, resulting in invalid XML that cannot be used. There's one more online question about this, unresolved.
So if I try echo "bug";
I get 4 bytes, not 3: 0a 62 75 67
However, when using WAMP server locally (PHP 5.4.3/Apache 2.4.2), I get 3 bytes: 62 75 67
.
- Is this a known bug/feature?
- Is it a configuration issue?
- Which is to blame, Apache or PHP?
- Do I have to upgrade my servers? I'd rather not.