I'm using PHP to output custom XML based upon values stored in a MySQL database. I have the following at the start of the condition:
echo '<?xml version="1.0" encoding="UTF-8"?>';
(I've also tried this variation:
echo "<?xml version='1.0' encoding='UTF-8'?>";
to no avail.)
However, this is always outputted (in every browser and even when viewed as a downloaded file from wget
) as:
<?xml version=1.0 encoding=UTF-8 ?>
Somewhere along the line, the single quotes around the version number and encoding got dropped. Where did I go wrong and what can I do to fix this? I'm getting errors from my parser and I believe it's because this declaration is not following the XML standard of having either single or double quotes around these values.
I think this is because the content type of your document is already set to text/html (by default by php).
The solution to this is to set this as a header rather than echo it.
eg :
header ("Content-Type:text/xml");
to set the charset :
header('Content-Type: text/xml; charset=utf-8');
And make sure that you set this BEFORE you output (echo) anything else.
Hope that helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With