Saturday, 4 April 2015

Loading an XML file from a string in PHP



I'm trying to load a DOM using simplexml_load_string in PHP, but program always terminates right where the call is (nothing after the call gets executed). I've loaded the xml from a file into a string using



$source = file_get_contents("/path/to/file.xml");


Now, calling echo $source; returns the full output of the xml file in my browser. This is the source I get in browser:



<xml>
<title>Title</title>
<date>4 April 2015</date>
<content>
//...HTML content...//
</content>
</xml>


However, when the program calls



$xml = simplexml_load_string($source);


the program terminates and anything after that statement doesn't run. I've been through the docs and searched for hours now and can't seem to find anything like this. Before trying this method to construct the DOM I tried using simplexml_load_file with identical results. Has anyone seen something like this?


No comments:

Post a Comment