Link to home
Start Free TrialLog in
Avatar of Destiny Amana
Destiny AmanaFlag for Nigeria

asked on

How do I convert a HTTP GET Request in PHP into an ARRAY when the results return as an xml

I have to query a url with http get and then utilise the results which return with XML.

https://cipg.stanbicibtcbank.com/MerchantServices/UpayTransactionStatus.ashx?MERCHANT_ID=06412&ORDER_ID=2014111209310244

How would I accomplish this please?
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

Read the return file as an xml using any of the php library functions. For example simplexml_load_string.

http://php.net/manual/en/function.simplexml-load-string.php


Here is an article on reading and parsing a complex xml.

https://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_11342-Reading-XML-Namespaces-using-PHP-Without-regex.html
Avatar of Destiny Amana

ASKER

so with the simplexml function,

would my syntax be




<?php
$url = "https://cipg.stanbicibtcbank.com/MerchantServices/UpayTransactionStatus.ashx?MERCHANT_ID=06412&ORDER_ID=2014111209310244";

$xml = simplexml_load_string($url);

print_r($xml);
?>
SOLUTION
Avatar of Chris Harte
Chris Harte
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
This is exactly what I wanted help with, i have done it with ASP, but I am pretty new to PHP.

But the output comes as an array, if I want to work with any of the output like [StatusCode] how would i address the code  with an if statement

if statuscode = "00" then
 do this
else
 do that
end if statement
ASKER CERTIFIED 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
Munterman , you da Man! thanks a lot for these insights. Can I ask for a small favour, I want the values to be stored into a single variable

datalog = ""
foreach ($xml as $key => $value)
{
    datalog =  "$key => $value <br />";
}

something like this so I can log ALL the value.. Can you advise on this as well.
You just have to cast it as an array

$datalog = (array)$xml;