Abbe Abbe - 1 year ago 117
PHP Question

file_get_contents() removes XML tags

In the browser the following url shows up as a regular XML file. but when I'm using


it removes all XML tags and just returns the containing text. Why is this happening and how do I avoid it?

Some response headers:

array(5) {
[0]=> string(15) "HTTP/1.1 200 OK"
[1]=> string(35) "Date: Thu, 01 Jan 2015 20:07:04 GMT"
[2]=> string(25) "Server: Apache-Coyote/1.1"
[3]=> string(43) "Content-Type: application/xml;charset=UTF-8"
[4]=> string(17) "Connection: close"

Answer Source

Unable to reproduce:


header('Content-Type: text/plain; charset=utf-8');
echo substr(file_get_contents(''), 0, 256);

<?xml version="1.0" encoding="UTF-8"?><pres:item xmlns:pres=""><pres:id>10028201230001</pres:id><pres:entityUri></pres:entityUri><pres:type>Kulturlämning</pres:type><pres

So answer is: Works fine.

You perhaps look at the response in the browser which removes the tags? This at least would be a common mistake some users on Stackoverflow ask about.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download