Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting XML file content as string in php

Tags:

php

xml

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.

like image 472
Kiren S Avatar asked Aug 03 '26 12:08

Kiren S


1 Answers

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

like image 171
leuchtdiode Avatar answered Aug 06 '26 02:08

leuchtdiode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!