[ACCEPTED]-PHP header for xml with utf-8-header

Accepted answer
Score: 14

The header() function just modifies HTTP headers. The 10 code you posted sets a Content-Type header, which is 9 important for telling browsers and other 8 clients what type of file you're serving.

The 7 <?xml version="1.0"?> line you're talking about is part of the 6 document itself, and not affected by the 5 HTTP headers.

Your tags say you're using 4 DOM to create your XML document. If you 3 change your DomDocument constructor to also 2 pass the charset,

$doc = new DomDocument('1.0', 'UTF-8');

It should output that charset 1 in the XML document.

Score: 2

header just sets a HTTP header in the result. PHP 8 doesn't do anything else with the value, so 7 it's up to you to make sure it's being used 6 properly.

If you're using an XML library 5 to generate your XML (including the prologue), check 4 the documentation for that library. If you're 3 outputting the XML "by hand" (o, you need 2 to add the necessary attribute to the prologue 1 yourself.

Score: 0

You can also use

<?php echo '<?xml version"1.0" encoding="UTF-8"?>'; ?>


More Related questions