file_get_content to simplexml_load_file PHP
Posted on 2013-11-05
I am currently working on a PHP project that implements calls to Web Services as part of its feature.
When a call is made to a URI, it is made using file_get_content. The result is an XML string. However, since I am more comfortable working with simplexml_load_file, I would like to convert the result that I get from the file_get_content call to a form that can be used by simplexml_load_file.
Something like this:
$xml = file_get_contents($request, false, $context);
//Change $xml to a format that can be used by simplexml_load_file
$ChangedXML = simplexml_load_file($xml);
- When I try to make the call directly to the URI using simplexml_load_file, it throws an error. Besides, I would rather use what the API has recommended me to use, and they have recommended file_get_content to get the XML details when making calls.
- Also, when I try to directly load the result into simplexml_load_file, it throws an error.
It looks like some sort of formatting needs to be done to convert the results obtained from file_get_content to something that simplexml_load_file can use to load.
I am relatively new to PHP and would seek some assistance to this effect. I thank you all in advance.