Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>/** * Rechnet den gegebenen Betrag von einer Währung in eine andere um * @param FLOAT $value * @param STRING $fromCurrency=USD Ursprungswärung des Betrags * @param STRING $toCurrency=EUR Zielwärhung, in die umgerechnet wird * @param BOOL $round=true Wenn aktiviert, wird der errechnete Wert auf 2 Nachkommastellen kaufmännisch gerundet * @return ARRAY [timestamp][datetime_iso][datetime_de][value][from][to][result] */ function calcCurrency($value=0, $fromCurrency='USD', $toCurrency='EUR', $round=true) { $timestamp = time(); $fromCurrency = preg_replace('[^A-Z]', '', strtoupper(trim($fromCurrency))); $toCurrency = preg_replace('[^A-Z]', '', strtoupper(trim($toCurrency))); $round = (bool) $round; $wrongJSON = file_get_contents("http://www.google.com/ig/calculator?hl=en&amp;q=1$fromCurrency=?$toCurrency"); $search = array('lhs', 'rhs', 'error', 'icc'); $replace = array('"lhs"', '"rhs"', '"error"', '"icc"'); $json = str_replace($search, $replace, $wrongJSON); $jsonData = json_decode($json, true); if ('' !== $jsonData['error']) throw new Exception('FEHLER: '.$jsonData['error']); $rhs = explode(' ', $jsonData['rhs'], 2); $calcValue = floatval(0.00); $value = floatval($value); $ratio = floatval($rhs[0]); // Gültigkeitsprüfungen if ($value &lt; 0) throw new Exception('Umzurechnender Wert darf nicht negativ sein.'); // Plausibilitätsprüfung der eingestellten Währung und Festlegung if ($toCurrency == $fromCurrency) { // Ursprungswährung = Zielwährung | Es erfolgt keine Berechnung $calcValue = $value; $ratio = 1; } else { $calcValue = floatval($value * $ratio); } // Array mit Rückgabewerten erzeugen und zurück geben return array( 'timestamp' =&gt; $timestamp, 'datetime_iso' =&gt; date('Y-m-d H:i:s', $timestamp), 'datetime_de' =&gt; date('d.m.Y H:i:s', $timestamp), 'value' =&gt; $value, 'from' =&gt; $fromCurrency, 'to' =&gt; $toCurrency, 'ratio' =&gt; round($ratio, 6), 'result' =&gt; (true===$round) ? round($calcValue, 2) : $calcValue ); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload