Php – What php function can display formated XHTML from a XML file


Ive been trying to display formatted content blocks from a xml file with no luck. Ive been using simplexml_load_file and other varients which Im now seeing cannot deal with the xhtml tags within the called tag … eg.

//php contents
 <?php $xml=simplexml_load_file("file.xml");
 echo ($xml->entry); ?>

//xml contents
 <p>This does not work</p>


 <entry>This works</entry>

can someone please tell me which php function can do this from an xml file and or
what is the best way to display the contents with xhtml formatting?

Im trying to dynamically load content to a webpage without having to build too many pages. I like the idea of having all my content in one xml file for easy edits.

Theres not enough content to justify a database yet.

Thanks in advance

Best Solution

You can try dumping the contents of a certain simplexml node (in this case: $xml->entry) using the asXml function.

echo $xml->entry->asXml();

Check the php documentation on simplexml here (link to the asXml() call):

Simplexml documentation

Related Question