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
|
<?
/*
* Canadian Weather Script
* Gets Weather Information and Displays it on your Website
*
* Author : JMan
* HomePage : www.bedpan.ca
* Email : jman@bedpan.ca
*/
include("cache.php");
$imagedir = "images/weather/";
//directory with your image icons WITH the trailing slash
$cached = cache("weather");
if ($cached){
$matches = $cached;
}else{
$fp = @fsockopen("www.weatheroffice.ec.gc.ca", 80, $errno, $errstr, "1");
if ($fp){
fclose($fp);
$site = file_get_contents("http://www.weatheroffice.ec.gc.ca/forecast/city_e.html?on-82&unit=m&b_templatePrint=true");
$site = str_replace(" ", "", $site);
$site = str_replace(" ", "", $site);
$site = str_replace("\n", "", $site);
$site = str_replace("\r", "", $site);
$site = str_replace("<li class=\"pop", "<font color=\"green", $site);
$site = str_replace("<li class=\"high", "<font color=\"red", $site);
$site = str_replace("<li class=\"low", "<font color=\"blue", $site);
$site = str_replace("</li>", "</font>", $site);
$site = str_replace("</font><font", "</font><Br><font", $site);
$startgrab = strpos($site , '<div xmlns="" id="cityf">');
$start = strpos($site , '<div id="f1">', $startgrab);
$finish = strpos($site , '</div></div>', $start) + 8;
$length = $finish-$start;
$code=Substr($site , $start, $length);
preg_match_all("'<h3>(.*?)/p></div>'", $code, $matches);
$matches = $matches[1];
cache("weather", 3600, $matches);
}
}
if ($matches){
foreach ($matches as $b => $r){
preg_match_all('/(.*?)<\/h3>.*?\/weathericons\/(.*?)".*?<ul>(.*?)<\/ul><p>(.*?)</', $matches[$b], $matches[$b]);
}
$wdth = intval(100/count($matches));
$weather = "<table width=\"100%\">\n";
for ($g=1; $g<5; $g++){
$weather .= "<tr>\n";
foreach ($matches as $b => $r){
if ($g==1) $matches[$b][$g][0] = "<b>".ucwords($matches[$b][$g][0])."</b>";
if ($g==2) $matches[$b][$g][0] = "<img src=\"$imagedir".($matches[$b][$g][0])."\">";
elseif ($g==4) $matches[$b][$g][0] = ucwords($matches[$b][$g][0]);
$weather .= "<td width=\"$wdth%\" style=\"font-size: 10px; text-align:center;\">".$matches[$b][$g][0]."</td>\n";
}
$weather .= "</tr>\n";
}
$weather .= "</table>";
}
echo $weather;
?>
|