<?php
function tcmbDovizKuru()
{
try
{
$tcmbXML = file_get_contents("http://www.tcmb.gov.tr/kurlar/today.xml");
$xmlVeri = new SimpleXMLElement($tcmbXML);
$dovizAdi = $xmlVeri->xpath("/Tarih_Date/Currency//@Kod");
$alis = $xmlVeri->xpath("/Tarih_Date/Currency/ForexBuying");
$satis = $xmlVeri->xpath("/Tarih_Date/Currency/ForexSelling");
$deger = '<table><tr><th>Döviz</th><th>Alış</th><th>Satış</th></tr>';
$size = sizeof($alis);
for($i=0; $i<$size; $i++):
$deger .='
<tr>
<td>' . $dovizAdi[$i] . '</td>
<td>' . $alis[$i] . '</td>
<td>' . $satis[$i] . '</td>
</tr>';
endfor;
$deger .= '</table>';
echo $deger;
}
catch(Exception $ex)
{
echo '<div>Bilgiler alınamadı' .$ex->getMessage() .'")</div>';
}
}
tcmbDovizKuru();
?>
Peki buradan gelen bilgileri kısıtlamak istesek?
Mesela sadece USD, EUR ve GBP bilgilerini almak istesek ne yapmak gerekir?