我正在使用SimplePie进行雅虎天气预报。我在新服务器上,现在输出如下:
set_feed_url($path . $code); $feed->set_item_class('SimplePie_Item_YWeather'); $feed->init(); function time2minuts($time) { $minuts = 0; $atime = explode(" ", $time); $ttime = explode(":", $atime[0]); if ($atime[1] == "pm") { if ((int)$ttime[0]!=12) $ttime[0] = $ttime[0] + 12; } $minuts = (int)$ttime[0] * 60 + (int)$ttime[1]; return $minuts; } $weather = $feed->get_item(0); $fore = $weather->get_forecasts(); $unit = $weather->get_units_temp(); $ampm = "n"; // indica noche $icon = $weather->get_condition_code(); // Calculamos la hora de Mallorca en minutos $curday = time2minuts(date("g:i a")); //echo $curday.'---'.date('h:m d.m.y').'---'.date("g:i a"); $iniday = time2minuts($weather->get_sunrise()); $endday = time2minuts($weather->get_sunset()); if ($curday > $iniday && $curday < $endday) { $ampm = "d"; // indica dia } $land = $weather->get_country(); if($land == 'Spain') { $land = 'Spanien'; } ?>
这是我的PHP代码。我的PHP版本是5.5.9-1ubuntu4.6 simplepie 1.3.1
感谢您的帮助,
mallmis
答案 0 :(得分:0)
感谢您的快速回复。
我的脚本正在使用旧服务器。但我会发帖:
<?
require("simplepie.inc");
require("simplepie_yahoo_weather.inc");
$code = "769293"; // Menorca 12517557
$path = "http://weather.yahooapis.com/forecastrss?u=c&w=";
$feed = new SimplePie();
$feed->set_feed_url($path . $code);
$feed->set_item_class('SimplePie_Item_YWeather');
$feed->init();
function time2minuts($time)
{
$minuts = 0;
$atime = explode(" ", $time);
$ttime = explode(":", $atime[0]);
if ($atime[1] == "pm") {
if ((int)$ttime[0]!=12) $ttime[0] = $ttime[0] + 12;
}
$minuts = (int)$ttime[0] * 60 + (int)$ttime[1];
return $minuts;
}
$weather = $feed->get_item(0);
$fore = $weather->get_forecasts();
$unit = $weather->get_units_temp();
$ampm = "n"; // indica noche
$icon = $weather->get_condition_code();
// Calculamos la hora de Mallorca en minutos
$curday = time2minuts(date("g:i a"));
//echo $curday.'---'.date('h:m d.m.y').'---'.date("g:i a");
$iniday = time2minuts($weather->get_sunrise());
$endday = time2minuts($weather->get_sunset());
if ($curday > $iniday && $curday < $endday) {
$ampm = "d"; // indica dia
}
$land = $weather->get_country();
if($land == 'Spain')
{
$land = 'Spanien';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Yahoo Weather</title>
<style type="text/css">
<!--
body {
font-family: "Trebuchet MS", Tahoma, Verdana;
font-size: 12px;
font-weight: normal;
color: #777777;
text-decoration: none;
background-color: #FFFFFF;
}
#weather {
width: 240px;
height: 120px;
margin-left: 10px;
}
#current {
width: 240px;
height: 120px;
text-align: right;
color: #FFFFFF;
font-weight: bold;
}
#current #temp {
font-size: 24px;
font-style: normal;
padding-top: 40px;
padding-right: 16px;
}
#current #fore {
padding-right: 16px;
font-size: 11px;
}
#current #city {
padding-right: 16px;
}
-->
</style>
</head>
<body>
<div id="weather" style="background:url('icon<?php echo $ampm; ?>.png') no-repeat 40px 40px;">
<div id="current" style="background:url('http://l.yimg.com/us.yimg.com/i/us/nws/weather/gr/<?php echo $icon . $ampm . ".png"; ?>') no-repeat 0px -10px;">
<div id="temp"><?php echo $weather->get_temperature(); ?>°<?php echo $unit; ?></div>
<div id="fore"><?php echo $fore[0]->get_low() . "°" . $unit; ?>
bis <?php echo $fore[0]->get_high() . "°" . $unit; ?></div>
<div id="city"><?php echo 'Mallorca' . ", " . $land; ?></div>
</div>
</div>
</body>
</html>
我认为它确实对我的新服务器做了一些事情。
干杯,
mallmis