Wer das Modul Add Block Feature v.1.0.0 installiert hat, kann diesen Code als PHP Block einfügen.
Mit diesen Code erhaltet Ihr einen Eurorechner der von Euro oder in Euro Währungen umrechnet
[php]
class Ecb{
private $currencie_url="http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml";
private $cur_array=array();
private static $cur_descript=array(
'EUR'=>'Euro','USD'=>'US dollar',
'JPY'=>'Japanese yen','BGN'=>'Bulgarian lev',
'CYP'=>'Cyprus pound','CZK'=>'Czech koruna',
'DKK'=>'Danish krone','EEK'=>'Estonian kroon',
'GBP'=>'Pound sterling','HUF'=>'Hungarian forint',
'LTL'=>'Lithuanian litas','LVL'=>'Latvian lats',
'MTL'=>'Maltese lira', 'MXN'=>'Mexican peso',
'PLN'=>'Polish zloty', 'BRL'=>'Brasilian real',
'RON'=>'New Romanian leu 2','SEK'=>'Swedish krona',
'SKK'=>'Slovak koruna','CHF'=>'Swiss franc',
'ISK'=>'Icelandic krona','NOK'=>'Norwegian krone',
'HRK'=>'Croatian kuna','RUB'=>'Russian rouble',
'TRY'=>'New Turkish lira 3','AUD'=>'Australian dollar',
'CAD'=>'Canadian dollar','CNY'=>'Chinese yuan renminbi',
'HKD'=>'Hong Kong dollar','IDR'=>'Indonesian rupiah',
'KRW'=>'South Korean won','MYR'=>'Malaysian ringgit',
'NZD'=>'New Zealand dollar','PHP'=>'Philippine peso',
'SGD'=>'Singapore dollar','THB'=>'Thai baht',
'INR'=>'Indian rupee','ZAR'=>'South African rand' );
protected $cach_file_name= 'currency.txt';//standard in gleichem ordner.
protected $cach_time=3600;//eine Stunde cachen.
public function __construct()
{
$this->cach_file_name=dirname( __FILE__ ).DIRECTORY_SEPARATOR.$this->cach_file_name;
if(!file_exists($this->cach_file_name)
(file_exists($this->cach_file_name) && (filemtime($this->cach_file_name)+$this->cach_time)<time() ) )
{
$this->init_currencie();
}
else
{
$this->cur_array=unserialize(file_get_contents($this->cach_file_name));
}
$this->cur_array['EUR']=1.0;
}
public function calculate($amount,$curr,$curr_to)
{
return $this->getRate($curr_to)*$amount/$this->getRate($curr);
}#end calculate
public static function getDescription($val=false)
{
return $val?(self::$cur_descript[$val]) : (self::$cur_descript);
}#end getDescription
public function getRate($currencie_short)
{
return isset($this->cur_array[$currencie_short])?$this->cur_array[$currencie_short]:false;
}#end getRate
public function getCurrencieAll()
{
return $this->cur_array;
}#end getCurrencieAll
private function init_currencie()
{
preg_match_all("#currency\='(.{3})'\s+rate\='([^']+)'#",file_get_contents($this->currencie_url),$array);
if(count($array>2))
{
$this->cur_array=array_combine($array[1],$array[2]);
file_put_contents($this->cach_file_name,serialize($this->cur_array));
}
else die('Bug in '.__FILE__.' Line:'.__LINE__);
}
}
$geld=new Ecb;
#simple example
echo '<div style="padding-left:10px;">';
echo '<form method="post">';
echo 'Betrag: <input type="text" name="betrag" value="100" class="input"><br />';
$sel='<select name="%s" class="select">';
foreach(Ecb::getDescription() as $k=>$v)
{
$sel.="<option value=\"{$k}\">{$k} : {$v}</option>";
}
$sel.='</select>';
printf('Von:'.$sel.' In:'.$sel,'von','in');
echo ' <input type="submit" class="button" value="Rechnen"></form>';
if(isset($_POST['von'],$_POST['in'],$_POST['betrag']) && is_numeric($_POST['betrag']))
{
echo '<h3>Für '.$_POST['betrag'].' '.Ecb::getDescription($_POST['von']).' bekommen Sie '.
round($geld->calculate($_POST['betrag'],$_POST['von'],$_POST['in']),2).' '.
Ecb::getDescription($_POST['in']).'</h3>';
}
echo '<h5>Aktuele Tabelle</h5><table width="300" cellpadding="0" cellspacing="4" border="0">
<tr>
<td width="23%"><b>Kürzel</b></td>
<td width="38%"><b>Name</b></td>
<td width="38%"><b>Eurokurs</b></td>
</tr>';
foreach($geld->getCurrencieAll() as $geldk=>$value)
{
echo "<tr><td>{$geldk}</td><td>".Ecb::getDescription($geldk)."</td><td>{$value}</td></tr>";
}
echo "</table></div>";
[/php]
Mit diesen Code erhaltet Ihr einen Eurorechner der von Euro oder in Euro Währungen umrechnet
[php]
class Ecb{
private $currencie_url="http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml";
private $cur_array=array();
private static $cur_descript=array(
'EUR'=>'Euro','USD'=>'US dollar',
'JPY'=>'Japanese yen','BGN'=>'Bulgarian lev',
'CYP'=>'Cyprus pound','CZK'=>'Czech koruna',
'DKK'=>'Danish krone','EEK'=>'Estonian kroon',
'GBP'=>'Pound sterling','HUF'=>'Hungarian forint',
'LTL'=>'Lithuanian litas','LVL'=>'Latvian lats',
'MTL'=>'Maltese lira', 'MXN'=>'Mexican peso',
'PLN'=>'Polish zloty', 'BRL'=>'Brasilian real',
'RON'=>'New Romanian leu 2','SEK'=>'Swedish krona',
'SKK'=>'Slovak koruna','CHF'=>'Swiss franc',
'ISK'=>'Icelandic krona','NOK'=>'Norwegian krone',
'HRK'=>'Croatian kuna','RUB'=>'Russian rouble',
'TRY'=>'New Turkish lira 3','AUD'=>'Australian dollar',
'CAD'=>'Canadian dollar','CNY'=>'Chinese yuan renminbi',
'HKD'=>'Hong Kong dollar','IDR'=>'Indonesian rupiah',
'KRW'=>'South Korean won','MYR'=>'Malaysian ringgit',
'NZD'=>'New Zealand dollar','PHP'=>'Philippine peso',
'SGD'=>'Singapore dollar','THB'=>'Thai baht',
'INR'=>'Indian rupee','ZAR'=>'South African rand' );
protected $cach_file_name= 'currency.txt';//standard in gleichem ordner.
protected $cach_time=3600;//eine Stunde cachen.
public function __construct()
{
$this->cach_file_name=dirname( __FILE__ ).DIRECTORY_SEPARATOR.$this->cach_file_name;
if(!file_exists($this->cach_file_name)
(file_exists($this->cach_file_name) && (filemtime($this->cach_file_name)+$this->cach_time)<time() ) )
{
$this->init_currencie();
}
else
{
$this->cur_array=unserialize(file_get_contents($this->cach_file_name));
}
$this->cur_array['EUR']=1.0;
}
public function calculate($amount,$curr,$curr_to)
{
return $this->getRate($curr_to)*$amount/$this->getRate($curr);
}#end calculate
public static function getDescription($val=false)
{
return $val?(self::$cur_descript[$val]) : (self::$cur_descript);
}#end getDescription
public function getRate($currencie_short)
{
return isset($this->cur_array[$currencie_short])?$this->cur_array[$currencie_short]:false;
}#end getRate
public function getCurrencieAll()
{
return $this->cur_array;
}#end getCurrencieAll
private function init_currencie()
{
preg_match_all("#currency\='(.{3})'\s+rate\='([^']+)'#",file_get_contents($this->currencie_url),$array);
if(count($array>2))
{
$this->cur_array=array_combine($array[1],$array[2]);
file_put_contents($this->cach_file_name,serialize($this->cur_array));
}
else die('Bug in '.__FILE__.' Line:'.__LINE__);
}
}
$geld=new Ecb;
#simple example
echo '<div style="padding-left:10px;">';
echo '<form method="post">';
echo 'Betrag: <input type="text" name="betrag" value="100" class="input"><br />';
$sel='<select name="%s" class="select">';
foreach(Ecb::getDescription() as $k=>$v)
{
$sel.="<option value=\"{$k}\">{$k} : {$v}</option>";
}
$sel.='</select>';
printf('Von:'.$sel.' In:'.$sel,'von','in');
echo ' <input type="submit" class="button" value="Rechnen"></form>';
if(isset($_POST['von'],$_POST['in'],$_POST['betrag']) && is_numeric($_POST['betrag']))
{
echo '<h3>Für '.$_POST['betrag'].' '.Ecb::getDescription($_POST['von']).' bekommen Sie '.
round($geld->calculate($_POST['betrag'],$_POST['von'],$_POST['in']),2).' '.
Ecb::getDescription($_POST['in']).'</h3>';
}
echo '<h5>Aktuele Tabelle</h5><table width="300" cellpadding="0" cellspacing="4" border="0">
<tr>
<td width="23%"><b>Kürzel</b></td>
<td width="38%"><b>Name</b></td>
<td width="38%"><b>Eurokurs</b></td>
</tr>';
foreach($geld->getCurrencieAll() as $geldk=>$value)
{
echo "<tr><td>{$geldk}</td><td>".Ecb::getDescription($geldk)."</td><td>{$value}</td></tr>";
}
echo "</table></div>";
[/php]
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von olib32 ()