galaxyg
galaxyg

Reputation: 53

Unwanted <head /> appearing in PHP generated XML - why?

The PHP code is this:-

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<example>\n";
echo "</example>";

The result is this:-

<?xml version="1.0" encoding="utf-8" /?>
<head/><example>
</example>

Why is this < head/ > tag appearing? How can I get rid of it?

Upvotes: 1

Views: 451

Answers (1)

Arnaud Le Blanc
Arnaud Le Blanc

Reputation: 99921

Most probably, you are sending the XML with a HTML content-type, and there is a HTML post processor like mod_pagespeed or cloudflare taking place between this PHP script and the browser.

You should try sending the XML with a proper content type like application/xml:

header("Content-Type: application/xml");

Upvotes: 5

Related Questions