Scaltro
Гуру форума
- Регистрация
- 15 Сен 2007
- Сообщения
- 1.170
- Реакции
- 79
- Автор темы
- #1
Код курса валют с сайта центробанка:
Вставляю его в mod_php в joostina и при отображении выдаёт:
И потом только таблицу курсов, помогите избавиться от этих ошибочек :bc:
Код:
<?php
$ch = curl_init();
if (!$ch) {
die("Couldn't initialize a cURL handle");
}
// Ставим переменные CURL
$ret = curl_setopt($ch, CURLOPT_URL, "http://export.rbc.ru/free/cb.0/free.fcgi?period=DAILY&tickers=null&lastdays=5&separator=%3B&data_format=BROWSER");
$ret = curl_setopt($ch, CURLOPT_HEADER, 0);
$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$ret = curl_setopt($ch, CURLOPT_MUTE, 5);
// Запускаем
$ret = curl_exec($ch);
curl_close($ch); // ...и закрываем
$ret = explode ("\n", $ret);
foreach ($ret as $key => $value) {
$temp = explode (";", $value);
$result[$temp[0]][] = $temp[1]."|".$temp[5];
}
if (!$result['USD'][0]) $error = 1;
function result_output($result) {
echo "<table cellpadding=0 cellspacing=2><tr><td colspan=2 align=right style='font-family: Courier New, Arial, Times New Roman; font-size: 11px;'>";
$count = count($result['USD']);
$temp2 = explode ("|", $result['USD'][$count-1]);
$temp2 = explode ("-", $temp2[0]);
$date = $temp2[2].".".$temp2[1].".".$temp2[0];
echo "<i>";
echo $date;
echo " / ";
$temp2 = explode ("|", $result['USD'][$count-2]);
$temp2 = explode ("-", $temp2[0]);
$date = $temp2[2].".".$temp2[1].".".$temp2[0];
echo $date;
$rate1 = explode ("|", $result['USD'][$count-1]);
$rate1 = $rate1[1];
$rate2 = explode ("|", $result['USD'][$count-2]);
$rate2 = $rate2[1];
echo "</i></td></tr><tr><td><img src='img/ico/pur_z.gif' width='16' height='16' hspace='4'></td><td style='font-family: Courier New, Arial, Times New Roman; font-size: 11px;'>";
echo "<b>USD</b>: ".str_pad($rate1, 7, "0");
echo " / ";
echo str_pad($rate2, 7, "0");
$temp = round($rate1 - $rate2, 4);
if ($temp > 0) {
$temp = "+".$temp;
echo " <img src='img/ico/arrow_g.gif' width='10' height='10'> ";
} elseif ($temp == 0) {
echo " <img src='img/ico/arrow_g.gif' width='10' height='10'> ";
$temp = "0.0";
} else {
echo " <img src='img/ico/arrow_r.gif' width='10' height='10'> ";
}
$temp = str_pad($temp, 7, "0");
echo "<i>".$temp."</i>";
$rate1 = explode ("|", $result['EUR'][$count-1]);
$rate1 = $rate1[1];
$rate2 = explode ("|", $result['EUR'][$count-2]);
$rate2 = $rate2[1];
echo "</td></tr><tr><td><img src='img/ico/pur_e.gif' width='16' height='16' hspace='4'></td><td style='font-family: Courier New, Arial, Times New Roman; font-size: 11px;'>";
echo "<b>EUR</b>: ".str_pad($rate1, 7, "0");
echo " / ";
echo str_pad($rate2, 7, "0");
$temp = round($rate1 - $rate2, 4);
if ($temp > 0) {
$temp = "+".$temp;
echo " <img src='img/ico/arrow_g.gif' width='10' height='10'> ";
} elseif ($temp == 0) {
echo " <img src='img/ico/arrow_g.gif' width='10' height='10'> ";
$temp = "0.0";
} else {
echo " <img src='img/ico/arrow_r.gif' width='10' height='10'> ";
}
$temp = str_pad($temp, 7, "0");
echo "<i>".$temp."</i>";
$rate1 = explode ("|", $result['UAH'][$count-1]);
$rate1 = $rate1[1];
$rate2 = explode ("|", $result['UAH'][$count-2]);
$rate2 = $rate2[1];
echo "</td></tr><tr><td><img src='img/ico/pur_u.gif' width='16' height='16' hspace='4'></td><td style='font-family: Courier New, Arial, Times New Roman; font-size: 11px;'>";
echo "<b>UAH</b>: ".str_pad($rate1, 7, "0");
echo " / ";
echo str_pad($rate2, 7, "0");
$temp = round($rate1 - $rate2, 4);
if ($temp > 0) {
$temp = "+".$temp;
echo " <img src='img/ico/arrow_g.gif' width='10' height='10'> ";
} elseif ($temp == 0) {
echo " <img src='img/ico/arrow_g.gif' width='10' height='10'> ";
$temp = "0.0";
} else {
echo " <img src='img/ico/arrow_r.gif' width='10' height='10'> ";
}
$temp = str_pad($temp, 7, "0");
echo "<i>".$temp."</i></td></tr></table>";
}
if (!$error) result_output($result);
?>
Код:
Notice: Undefined offset: 1 in /tmp/htmlZohOty on line 22
Notice: Undefined offset: 5 in /tmp/htmlZohOty on line 22
Notice: Undefined variable: error in /tmp/htmlZohOty on line 114