2

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
  • 305,248
  • 71
  • 524
  • 547
Kiren S
  • 2,939
  • 5
  • 40
  • 68
  • 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

5

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
  • 184,866
  • 48
  • 414
  • 792
leuchtdiode
  • 467
  • 3
  • 12