Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mDelshad's avatar

get data from xml api

hi guys

i want get the currency rate from this api :

http://parsijoo.ir/api?serviceType=price-API&query=Currency

but this is xml api and I do not know how can i get data... i was convert this xml to json, With this code :

$response = file_get_contents('http://parsijoo.ir/api?serviceType=price-API&query=Currency');       
    $xml = simplexml_load_string($response);
    $json = json_encode($xml);
    $array = json_decode($json,TRUE);

But returns (name, price, change, percent ) values empty what is problem?

0 likes
1 reply
jlucia's avatar
jlucia
Best Answer
Level 8

Try this procedure to get the XML data and recognize the CDATA.

$xml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA);
1 like

Please or to participate in this conversation.