简体   繁体   中英

convert currency from xml + php

I have an xml source for daily currency http://www.tcmb.gov.tr/kurlar/today.xml

and i need to make a currency optional search for a portal. how can I get a specific data and convert from xml source? :/

i have a search form with:

  • price input
  • currency list box (euro, dollar)

and I need to convert the value from form for products price currency.

Appreciate helps!! thanks!!!

You can read the conversion rate like this:

<?php   

$x = simplexml_load_file('http://www.tcmb.gov.tr/kurlar/today.xml');

// Use GBP as an example
$code = 'GBP';

$nodes = $x->xpath('//Currency[@CurrencyCode="' . $code . '"]');

echo 'Buying Rate for ' . $code . 'is ' . (string)$nodes[0]->BanknoteBuying;


?>
$site = file_get_contents("http://www.tcmb.gov.tr/kurlar/today.xml"); 
preg_match_all("'EURO</CurrencyName><ForexBuying>(.*)</ForexBuying><ForexSelling>(.*)<CrossRateOther>(.*)<'U", $site, $durum);
preg_match_all("'POUND STERLING</CurrencyName><ForexBuying>(.*)</ForexSelling>(.*)<CrossRateOther>(.*)<'U", $site, $GBP);
$tl     = $durum[1][0]; 
$dolar  = $durum[3][0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM