at this link http://www.nbkr.kg/XML/daily.xml with PHP I need to get only the USD rate, namely the numbers themselves (which are in the Value tag).
please tell me how it can be implemented
at this link http://www.nbkr.kg/XML/daily.xml with PHP I need to get only the USD rate, namely the numbers themselves (which are in the Value tag).
please tell me how it can be implemented
Get data from xml using php as follows:
<?php // получаем с помощью curl или иным способом $res = <<<HTML <CurrencyRates Name="Daily Exchange Rates" Date="21.12.2018"><Currency ISOCode="USD"><Nominal>1</Nominal><Value>69,8381</Value></Currency><Currency ISOCode="EUR"><Nominal>1</Nominal><Value>79,7970</Value></Currency><Currency ISOCode="KZT"><Nominal>1</Nominal><Value>0,1883</Value></Currency><Currency ISOCode="RUB"><Nominal>1</Nominal><Value>1,0366</Value></Currency></CurrencyRates> HTML; $currencies = new SimpleXMLElement($res); function findCurrency($arr, $currencyCode) { $idx = 0; $find = false; while (!$find && ($idx < count($arr))) { if ($arr[$idx]->attributes()['ISOCode'] == $currencyCode) { $find = true; $searchResult = $arr[$idx]->Value; } $idx++; } return isset($searchResult) ? $searchResult : false; } echo findCurrency($currencies->Currency, 'USD'); $xml=simplexml_load_file('http://www.nbkr.kg/XML/daily.xml'); foreach($xml as $item){ if($item->attributes()['ISOCode']=='USD') echo $item->Value; } Source: https://ru.stackoverflow.com/questions/923648/
All Articles