yahoo-weerbericht

Gesponsorde koppelingen

PHP script bestanden

  1. yahoo-weerbericht

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
//data:
//link naar rss feed, te genereren op http://weather.yahoo.com/. Je geeft daar je woonplaats in en dan krijg je een nieuwsbericht van in jouw omgeving.
// Je kiest vervolgens het weer in graden Celsius
// dan klik je op de knop RSS-feed en kopieer je de URL hier

$rss = "http://weather.yahooapis.com/forecastrss?p=BEXX0013&u=c";

//link naar de afbeeldingen van de yeahoo site. Je kan dus ook je eigen afbeeldingen maken als je deze link aanpast
$imgsrc = "http://l.yimg.com/a/i/us/nws/weather/gr/";

//weercodes:
//je kan hier vertalingen of weerspreuken toevoegen. Dit is de standaard lijst van Yahoo.

$codes[0] = "tornado";
$codes[1] = "tropical storm";
$codes[2] = "hurricane";
$codes[3] = "severe thunderstorms";
$codes[4] = "thunderstorms";
$codes[5] = "mixed rain and snow";
$codes[6] = "mixed rain and sleet";
$codes[7] = "mixed snow and sleet";
$codes[8] = "freezing drizzle";
$codes[9] = "drizzle";
$codes[10] = "freezing rain";
$codes[11] = "showers";
$codes[12] = "showers";
$codes[13] = "snow flurries";
$codes[14] = "light snow showers";
$codes[15] = "blowing snow";
$codes[16] = "snow";
$codes[17] = "hail";
$codes[18] = "sleet";
$codes[19] = "dust";
$codes[20] = "foggy";
$codes[21] = "haze";
$codes[22] = "smoky";
$codes[23] = "blustery";
$codes[24] = "windy";
$codes[25] = "cold";
$codes[26] = "cloudy";
$codes[27] = "mostly cloudy"; //(night)
$codes[28] = "mostly cloudy"; //(day)
$codes[29] = "partly cloudy"; //(night)
$codes[30] = "partly cloudy"; //(day)
$codes[31] = "clear"; //(night)
$codes[32] = "sunny";
$codes[33] = "fair"; //(night)
$codes[34] = "fair"; // (day)
$codes[35] = "mixed rain and hail";
$codes[36] = "hot";
$codes[37] = "isolated thunderstorms";
$codes[38] = "scattered thunderstorms";
$codes[39] = "scattered thunderstorms";
$codes[40] = "scattered showers";
$codes[41] = "heavy snow";
$codes[42] = "scattered snow showers";
$codes[43] = "heavy snow";
$codes[44] = "partly cloudy";
$codes[45] = "thundershowers";
$codes[46] = "snow showers";
$codes[47] = "isolated thundershowers";
$codes[3200] = "not available";



//verwerking:
$xml = new SimpleXMLElement($rss, null, true);
if($xml) {

    //data ophalen
    //<yweather:condition  text="Partly Cloudy"  code="29"  temp="46"  date="Sat, 07 Mar 2009 7:20 pm CET" />

    $data = $xml->xpath("*/item/yweather:condition");
    foreach($data[0]->attributes() as $key =>$data) {
        $$key = $data;
    }

    
    //zien of het al licht is of niet:
    //<yweather:astronomy sunrise="7:14 am"   sunset="6:33 pm"/>

    $data = $xml->xpath("*/yweather:astronomy");
    foreach($data[0]->attributes() as $key =>$data) {
        $$key = $data;
    }

    
    $sunrise = strtotime(preg_replace("/[0-9]{1,2}\:[0-9]{1,2}\s[amp]{2}/i", $sunrise, $date));
    $sunset = strtotime(preg_replace("/[0-9]{1,2}\:[0-9]{1,2}\s[amp]{2}/i", $sunset, $date));
    $now = time();
    $moment = ($now >= $sunrise && $now <= $sunset) ? "d" : "n";
        
    
    //output
    $img = $imgsrc.$code.$moment.".png";
    
    echo('
    <div style="width: 163px; height: 140px; margin: -1px -5px -18px -5px; background:url(\''
.$img.'\'); background-position: -3px 10px; text-align: center;"><strong>Temperatuur: '.$temp.'&deg;C</strong><br />'.$codes[intval($code)].'</div>
    <div>&nbsp;</div>
    '
);
    
    
    //IE img hack: (werkt niet met background position, daarom niet toegevoeg aan het script..
    //_background-image/* */: none; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''.$img.'\', sizingMethod=\'crop\');


}


/*

VOORBEELD VAN EEN RSS response:


<?xml version="1.0" encoding="UTF-8" standalone="yes" ? >
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>

<title>Yahoo! Weather - Mechelen, BE</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Mechelen__BE/*http://weather.yahoo.com/forecast/BEXX0013_f.html</link>
<description>Yahoo! Weather for Mechelen, BE</description>
<language>en-us</language>
<lastBuildDate>Sat, 07 Mar 2009 7:20 pm CET</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Mechelen" region=""   country="BE"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="41"   direction="210"   speed="10" />
<yweather:atmosphere humidity="81"  visibility="6.21"  pressure="29.88"  rising="0" />
<yweather:astronomy sunrise="7:14 am"   sunset="6:33 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Mechelen, BE at 7:20 pm CET</title>
<geo:lat>51.03</geo:lat>
<geo:long>4.48</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Mechelen__BE/*http://weather.yahoo.com/forecast/BEXX0013_f.html</link>
<pubDate>Sat, 07 Mar 2009 7:20 pm CET</pubDate>
<yweather:condition  text="Partly Cloudy"  code="29"  temp="46"  date="Sat, 07 Mar 2009 7:20 pm CET" />
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/29.gif"/><br />
<b>Current Conditions:</b><br />
Partly Cloudy, 46 F<BR />
<BR /><b>Forecast:</b><BR />
Sat - Light Rain Late. High: 50 Low: 44<br />
Sun - Showers. High: 49 Low: 37<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Mechelen__BE/*http://weather.yahoo.com/forecast/BEXX0013_f.html">Full Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>
]]></description>
<yweather:forecast day="Sat" date="7 Mar 2009" low="44" high="50" text="Light Rain Late" code="11" />
<yweather:forecast day="Sun" date="8 Mar 2009" low="37" high="49" text="Showers" code="11" />
<guid isPermaLink="false">BEXX0013_2009_03_07_19_20_CET</guid>
</item>
</channel>
</rss><!-- api1.weather.re4.yahoo.com compressed/chunked Sat Mar  7 10:36:33 PST 2009 -->


*/


?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.