Meteorologia no meu site

Olá,

Arranja um site que tenha apenas o que pretendes,,, depois cria uma iframe com o seu conteúdo. Há métodos mais indicados, mas este é o mais acessivel...
 
E qual é a base do teu site? É dinâmico? Programado por ti? É um blog, Wordpress, Blogger? Se for Wordpress por exemplo é fácil arranjar um plugin.
 
Dá uma vista de olhos neste site para aprenderes a trabalhar com o SimpleXML. Em seguida, podes ir por exemplo ao site de meteorologia do Yahoo para obter os dados em formato XML. Por exemplo, se abrires isto, vais obter o RSS com as condições meteorológicas para Lisboa. Com esta informação, basta utilizares os conhecimentos adquiridos com o SimpleXML para procederes à extracção dos dados que pretendes.

Qualquer dúvida, coloca aqui.
 
Boas ja dei uma olhada e ja tive alguns resultados ... Tenho uma duvida tenho este codigo:

$teste2 = $rss->channel->description ;
echo $teste2 ;

O ficheiro xml(rss) tem varias linhas description como faxo para seleccionar a pretendida neste caso é a 3linha description ?

Abx
 
Boas, caso seja possível, coloca aqui o ficheiro XML de onde estás a tentar extrair a informação. De qualquer das formas, podes utilizar XPath (suportado pelo SimpleXML) para extrair o que pretendes. Por exemplo, para obteres todos os nós "description", podes fazer algo do género:

Código:
foreach ($rss->xpath('//description') as $description)
{
    echo $description;
}

O que a expressão diz é para obter todos os nós "description", a qualquer profundidade no documento XML.
 
Código:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="[URL]http://xml.weather.yahoo.com/ns/rss/1.0[/URL]" xmlns:geo="[URL]http://www.w3.org/2003/01/geo/wgs84_pos[/URL]#">
<channel>
<title>Yahoo! Weather - Leiria, PO</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Leiria__PO/*http://weather.yahoo.com/forecast/POXX0058_c.html</link>
<description>Yahoo! Weather for Leiria, PO</description>
<language>en-us</language>
<lastBuildDate>Sat, 11 Oct 2008 5:00 pm WEST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Leiria" region=""   country="PO"/>
<yweather:units temperature="C" distance="km" pressure="mb" speed="kph"/>
<yweather:wind chill="22"   direction="70"   speed="9.66" />
<yweather:atmosphere humidity="60"  visibility="9.99"  pressure="0"  rising="0" />
<yweather:astronomy sunrise="7:41 am"   sunset="7:01 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Leiria, PO at 5:00 pm WEST</title>
<geo:lat>39.75</geo:lat>
<geo:long>-8.78</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Leiria__PO/*http://weather.yahoo.com/forecast/POXX0058_c.html</link>
<pubDate>Sat, 11 Oct 2008 5:00 pm WEST</pubDate>
<yweather:condition  text="Partly Cloudy"  code="30"  temp="22"  date="Sat, 11 Oct 2008 5:00 pm WEST" />
<description><![CDATA[
<img src="[URL]http://l.yimg.com/us.yimg.com/i/us/we/52/30.gif"/><br[/URL] />
<b>Current Conditions:</b><br />
Partly Cloudy, 22 C<BR />
<BR /><b>Forecast:</b><BR />
Sat - Rain. High: 24 Low: 13<br />
Sun - PM Light Rain. High: 23 Low: 11<br />
<br />
<a href="[URL]http://us.rd.yahoo.com/dailynews/rss/weather/Leiria__PO/*http://weather.yahoo.com/forecast/POXX0058_c.html">Full[/URL] Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>
]]></description>
<yweather:forecast day="Sat" date="11 Oct 2008" low="13" high="24" text="Rain" code="12" />
<yweather:forecast day="Sun" date="12 Oct 2008" low="11" high="23" text="PM Light Rain" code="11" />
<guid isPermaLink="false">POXX0058_2008_10_11_17_00_WEST</guid>
</item>
</channel>
</rss><!-- api1.weather.re4.yahoo.com compressed/chunked Sat Oct 11 10:21:02 PDT 2008 -->



http://xml.weather.yahoo.com/forecastrss?p=POXX0058&u=c

So me entresava a imagem e a temperatura seria possivel?
 
Epa onde ponho esse codigo?

O meu codigo é este

PHP:
<?php // Load and parse the XML document 
$rss =  simplexml_load_file('http://xml.weather.yahoo.com/forecastrss?p=POXX0016&u=c');
$title =  $rss->channel->title;
?>
<html xml:lang="en" lang="en">
<head>
  <title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<?php
foreach ($rss->channel->item as $item) {
  echo "<h2><a href='" . $item->link . "'>" . $item->title . "</a></h2>";
  echo "<p>" . $item->description . "</p>";
 
  $teste = $rss->channel->lastBuildDate;
   $teste2 = $rss->channel->description ;
   echo $teste2 ;
  echo $teste ;
 
 
 }  
?>
</body>
</html>
 
Back
Topo