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

  • 3
    do you have a script to write? - Jean-Claude
  • download xml to a file and process it. There it is specifically USD indicated - maint

2 answers 2

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'); 
  • one
    If my answer answered the question, then please mark it as correct. This will help other participants to quickly find the right answers to their questions. - eustatos
  • @eustatos why such code gardens for problems solved in several lines? See my option. Maybe it should be easier? ;) - Nsk
  • @Nsk, and if a lot of currencies? Good currencies can not be very much) But I still do not want to run the excess in a cycle. - eustatos
  • @eustatos, found bucks do break; and do not run too much in the loop. - Nsk
 $xml=simplexml_load_file('http://www.nbkr.kg/XML/daily.xml'); foreach($xml as $item){ if($item->attributes()['ISOCode']=='USD') echo $item->Value; }