Rozz
Rozz

Reputation: 1

Read php file with content-type xml

I have a php file where I set the header to header ("content-type: text/xml");. When I try to read the file with simplexml_load_file() it returns `false. But if I set the extension to xml, the file will read correctly.

I use php 5.1.6. With version > 5.3 all works fine. Is this a bug in version 5.1.6. What could be the problem?

Thanks

Upvotes: 0

Views: 859

Answers (2)

Marc B
Marc B

Reputation: 360692

simple_xml_load_file('yourfile.php') will do a file-based open/read, and you'll be loading raw PHP code directly into simplexml. simple_xml_load_file('http://example.com/yourfile.php') will do a full-blown HTTP request and cause yourfile.php to be executed, at which point it should output the xml header and output xml text.

Upvotes: 0

Ēriks Daliba
Ēriks Daliba

Reputation: 718

Try get it as file and than load as string:

$str = file_get_contents($file);
$xml = simplexml_load_string($str);

Upvotes: 2

Related Questions