3

I want to display the content of a xml file as itself. I dont want to parse it, instead just read its content and display it.

I tried

$content = file_get_contents("test.xml") ;

But the $content has xml in it.ie when I var_dump($content) the output is string(899) " " Is it possible to read the the file without parsing. Help me please.

Thanks.

Gordon
  • 312,688
  • 75
  • 539
  • 559
Kiren S
  • 3,037
  • 7
  • 41
  • 69
  • Potential duplicates: [How to echo xml file in php](http://stackoverflow.com/q/1199595/367456); [file_get_contents() returns an empty string when authenticating, otherwise fine](http://stackoverflow.com/q/5954840/367456); [php - send and receive xml documents](http://stackoverflow.com/q/6779320/367456) – hakre Jun 21 '13 at 23:23

1 Answers1

6

This should solve it

$content = htmlentities(file_get_contents("test.xml"));

And this should solve it:

header("Content-Type: text/plain");
$content = file_get_contents("test.xml");
var_dump($content);

It tells the browser you're sending plain text so that the XML is not rendered as HTML tags (which then are unknown and hidden).

hakre
  • 193,403
  • 52
  • 435
  • 836
leuchtdiode
  • 477
  • 3
  • 12