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.

1

1 Answer 1

7

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.