-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.php
91 lines (76 loc) · 2.15 KB
/
weather.php
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
<?php
$apiKey = "your API key";
$cityId = "1176615";
$peshawer="1168197";
$charsadda="1181439";
$myapi="dczerobfed3882b1c9605a589d949a0b6fe";
$googleApiUrl = "http://api.openweathermap.org/data/2.5/weather?id=" . $peshawer . "&lang=en&units=metric&APPID=" . $apiKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $googleApiUrl);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
$currentTime = time();
?>
<!doctype html>
<html>
<head>
<title>Forecast Weather using OpenWeatherMap with PHP</title>
<style>
body {
font-family: Arial;
font-size: 0.95em;
color: #929292;
}
.report-container {
border: #E0E0E0 1px solid;
padding: 20px 40px 40px 40px;
border-radius: 2px;
width: 550px;
margin: 0 auto;
}
.weather-icon {
vertical-align: middle;
margin-right: 20px;
}
.weather-forecast {
color: #212121;
font-size: 1.2em;
font-weight: bold;
margin: 20px 0px;
}
span.min-temperature {
margin-left: 15px;
color: #929292;
}
.time {
line-height: 25px;
}
</style>
</head>
<body>
<div class="report-container">
<h2><?php echo $data->name; ?> Weather Status</h2>
<div class="time">
<div><?php echo date("l g:i a", $currentTime); ?></div>
<div><?php echo date("jS F, Y",$currentTime); ?></div>
<div><?php echo ucwords($data->weather[0]->description); ?></div>
</div>
<div class="weather-forecast">
<img
src="http://openweathermap.org/img/w/<?php echo $data->weather[0]->icon; ?>.png"
class="weather-icon" /> <?php echo $data->main->temp_max; ?>°C<span
class="min-temperature"><?php echo $data->main->temp_min; ?>°C</span>
</div>
<div class="time">
<div>Humidity: <?php echo $data->main->humidity; ?> %</div>
<div>Wind: <?php echo $data->wind->speed; ?> km/h</div>
</div>
</div>
</body>
</html>