Advertisement
Guest User

Currency

a guest
Oct 9th, 2016
1,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2.  
  3. Class Currency
  4. {
  5.     public static $soldRow = 6;
  6.     public static $url = "https://www.csob.cz/portal/lide/produkty/kurzovni-listky/kurzovni-listek/-/date/kurzy.txt";
  7.  
  8.     public function getActualSoldCurs($currency)
  9.     {
  10.         $output = false;
  11.         $lines = @file($this::$url);
  12.  
  13.         if ($lines === FALSE) {
  14.             throw new Exception("Currency list is inaccessible");
  15.         }
  16.  
  17.         $matches = preg_grep("/" . $currency . "/", $lines);
  18.  
  19.         if (count($matches) > 0) {
  20.             $contentLine = explode(";", reset($matches));
  21.             if (isset($contentLine[$this::$soldRow])) {
  22.                 $output = $contentLine[$this::$soldRow];
  23.             }
  24.         } else {
  25.             throw new Exception("Curse is not find in currency list.");
  26.         }
  27.         return $output;
  28.     }
  29. }
  30.  
  31. $currency = new Currency();
  32. try {
  33.     $course = $currency->getActualSoldCurs("USD");
  34.     echo $course;
  35. } catch (Exception $e) {
  36.     echo "Error: " . $e->getMessage();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement