Jump to content
php.lv forumi

LR Banka un Laika zinjas ;)))


sofTKiller

Recommended Posts

  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

bankas valūtu kursus var dabūt viņu lapā:

http://www.bank.lv/vk/xml.xml

 

Reiz sensenos laikos, kad man nebija pieejams ne SimpleXML, ne xml saimes funkcijas uzrakstīju pāris funkcijas:

 

<?php
function valuta($kods){
$str = file('http://www.bank.lv/vk/xml.xml');
$str = join('', array_slice($str, 4, count($str) - 7));
$str = str_replace("\n", '', $str);
$str = str_replace("\r", '', $str);
$str = preg_replace("/[\t]*/", '', $str);
$str = preg_replace("/[ ]*/", '', $str);
$str = str_replace('<Currency><ID>', '', $str);
$str = str_replace('</ID><Units>', '-', $str);
$str = str_replace('</Units><Rate>', '-', $str);
$str = str_replace('</Rate></Currency>', "\n", $str);
$valutas = explode("\n", $str);
foreach ($valutas as $valutaItem){
 $valutaInfo = explode('-', $valutaItem);
 $valutasListe[$valutaInfo[0]] = $valutaInfo[1] . $valutaInfo[0] . ' maksaa Ls ' . ($valutaInfo[2] * 1);
}
return $valutasListe[$kods];
}


function listvaluta(){
$str = file('valuta.xml');
$str = join('', array_slice($str, 4, count($str) - 7));
$str = str_replace("\n", '', $str);
$str = str_replace("\r", '', $str);
$str = preg_replace("/[\t]*/", '', $str);
$str = preg_replace("/[ ]*/", '', $str);
$str = str_replace('<Currency><ID>', '', $str);
$str = str_replace('</ID><Units>', '-', $str);
$str = str_replace('</Units><Rate>', '-', $str);
$str = str_replace('</Rate></Currency>', "\n", $str);
$valutas = explode("\n", $str);
foreach ($valutas as $valutaItem){
 $valutaInfo = explode('-', $valutaItem);
 $valutasListe[] = $valutaInfo[0];
}
return 'reku sheku, man ir shitaadi valuutas kursi: ' . join (', ', $valutasListe) . '. Ko vinji katrs noziimee, gan man neprasi :P';	
}
?>

Link to comment
Share on other sites

Specifiskāks, bet, domājams, ātrāks piemērs:

 

$text=@implode('',@file('http://www.bank.lv/vk/xml.xml'));
if (!$text)
die('Banka nav publicējusi šodienas kursus');
$text=str_replace('<Currency>','#',$text);
$text=strip_tags($text);
$text=explode('#',$text);
$els=count($text);
unset($text[0]);
$currencies=array();
while(--$els)
{
$lines=explode("\n",trim($text[$els]));
$currencies[trim($lines[0])]=array(trim($lines[1]),trim($lines[2]));
}
echo 'Amerikas dolāru kurss ir '.$currencies['USD'][1].' Ls par '.$currencies['USD'][0].' valūtas vienību.';
print '<pre>'.print_r($currencies,1).'</pre>';

Link to comment
Share on other sites

Ja ir pieejams SimpleXML, tad tas kljuust pavisam triviaali

 

<?php
$xmlstr = file_get_contents('xml.xml');
$xml = simplexml_load_string($xmlstr);
$currencyList = $xml -> body -> crates -> currencies -> currency;
foreach ($currencyList as $currencyItem){
 echo $currencyItem -> id . $currencyItem -> units . $currencyItem -> rate . "<br />";
}
?>

Link to comment
Share on other sites

  • 3 weeks later...

Biku neizprotu tavu problēmu, AJIEKCAHDP. Pats iedevi pie tam kautkādus nosaukumus, nevis konkrētu linku(s) no kurienes ņemt laika ziņas. Vari kautvai no šī paša www.pilsetas.lv ņemt, ja jau tas patīk. Tik ņem un cel augšā skriptu.

Edited by bubu
Link to comment
Share on other sites

te nu buus pats laika zinju kods, bet tas ir tikai Liepaajai! <_<

starp citu kaads laikam prasiija par resursiem...

nu luuk: http://gismeteo.ru/

pats kods:

 

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"

ID="fobos"

WIDTH="105" HEIGHT="51">

<param name="movie"

value="http://img.gismeteo.ru/flash/fw120x60.swf?index=26406&lang=en">'>http://img.gismeteo.ru/flash/fw120x60.swf?index=26406&lang=en">

<param name="quality" value="high">

<param name="bgcolor" value="#FFFFFF">

<param name="menu" value="false">

<param name="scale" value="exactfit"><embed

src="http://img.gismeteo.ru/flash/fw120x60.swf?index=26406&lang=en"

quality="high" bgcolor="#FFFFFF" WIDTH="120" HEIGHT="60"

TYPE="application/x-shockwave-flash"

PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">

</object>

Link to comment
Share on other sites


×
×
  • Create New...