Link to home
Start Free TrialLog in
Avatar of Mudasir Noorani
Mudasir NooraniFlag for United Kingdom of Great Britain and Northern Ireland

asked on

file_get_content to simplexml_load_file PHP

Hello Experts,

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

FYI:

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

Regards,

ref-IT
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mudasir Noorani

ASKER

Hey Chaps,

I'll have to tell you this, you guys are spot on !!

Ray_Paseur, I truly appreciate all the links and I'll definitely go through them.

Thanks a lot chaps,

red-IT
Thanks for the points and thanks for using EE, ~Ray