Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Class Currency
- {
- public static $soldRow = 6;
- public static $url = "https://www.csob.cz/portal/lide/produkty/kurzovni-listky/kurzovni-listek/-/date/kurzy.txt";
- public function getActualSoldCurs($currency)
- {
- $output = false;
- $lines = @file($this::$url);
- if ($lines === FALSE) {
- throw new Exception("Currency list is inaccessible");
- }
- $matches = preg_grep("/" . $currency . "/", $lines);
- if (count($matches) > 0) {
- $contentLine = explode(";", reset($matches));
- if (isset($contentLine[$this::$soldRow])) {
- $output = $contentLine[$this::$soldRow];
- }
- } else {
- throw new Exception("Curse is not find in currency list.");
- }
- return $output;
- }
- }
- $currency = new Currency();
- try {
- $course = $currency->getActualSoldCurs("USD");
- echo $course;
- } catch (Exception $e) {
- echo "Error: " . $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement