Created
April 7, 2016 07:23
-
-
Save inskyer/8115439ca4bf3e1e636c56b444e9dd28 to your computer and use it in GitHub Desktop.
currency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Получаем текущие курсы валют в rss-формате с сайта www.cbr.ru | |
| $content = get_content(); | |
| // Разбираем содержимое, при помощи регулярных выражений | |
| $pattern = "#<Valute ID=\"([^\"]+)[^>]+>[^>]+>([^<]+)[^>]+>[^>]+>[^>]+>[^>]+>[^>]+>[^>]+>([^<]+)[^>]+>[^>]+>([^<]+)#i"; | |
| preg_match_all($pattern, $content, $out, PREG_SET_ORDER); | |
| $dollar = ""; | |
| $euro = ""; | |
| foreach($out as $cur) | |
| { | |
| if($cur[2] == 978) $euro = str_replace(",",".",$cur[4]); | |
| } | |
| echo "<span id='cur_info'> 1€ - ".round($euro,2)."₽</span>"; | |
| function get_content() | |
| { | |
| // Формируем сегодняшнюю дату | |
| $date = date("d/m/Y"); | |
| // Формируем ссылку | |
| $link = "http://www.cbr.ru/scripts/XML_daily.asp?date_req=$date"; | |
| // Загружаем HTML-страницу | |
| $fd = fopen($link, "r"); | |
| $text=""; | |
| if (!$fd) echo "Запрашиваемая страница не найдена"; | |
| else | |
| { | |
| // Чтение содержимого файла в переменную $text | |
| while (!feof ($fd)) $text .= fgets($fd, 4096); | |
| } | |
| // Закрыть открытый файловый дескриптор | |
| fclose ($fd); | |
| return $text; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment