Destiny Amana
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?
https://cipg.stanbicibtcbank.com/MerchantServices/UpayTransactionStatus.ashx?MERCHANT_ID=06412&ORDER_ID=2014111209310244
How would I accomplish this please?
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);
?>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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;
$datalog = (array)$xml;
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