-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
117 lines (79 loc) · 3.38 KB
/
index.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
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
<?php
$weather = "";
$error = false;
if($_GET["city"]){
$url_contents = file_get_contents('http://api.openweathermap.org/data/2.5/weather?q='.str_replace(" ","",$_GET["city"]).',uk&appid=f53bf160c6d78a9ba2f925465f1035a8');
$weather_array = json_decode($url_contents,true);
//print_r($weather_array);
if($weather_array['cod'] == 200){
$weather = "The weather in ".$_GET['city']." is currently '".$weather_array['weather'][0]['description']."'.";
$temperature = intval($weather_array['main']['temp'] - 273);
$weather .= "The temperature is ".$temperature."°C . ";
$wind_speed = $weather_array['wind']['speed'];
$weather .= "and the Wind speed is ".$wind_speed." m/s.";
$error = false;
}
else{
$error = true;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Weather Forecast</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
<style type="text/css">
html{
background: url(bg.jpg) no-repeat center center fixed;
background-size: cover;
}
body{
background: none;
}
.container{
text-align: center;
font-family: cursive;
margin-top: 170px;
color: deepskyblue;
width: 450px;
}
input{
margin: 10px 0px;
}
#weather{
margin-top: 15px;
}
</style>
</head>
<body>
<div class="container">
<h1>Whats the Weather?</h1>
<form>
<div class="form-group">
<label for="exampleInputEmail1">Enter a city name</label>
<input type="text" class="form-control" id="city" name="city" placeholder="Eg. London" value="<?php
echo $_GET['city'] ; ?>">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<div id="weather">
<?php
if($weather){
echo '<div class="alert alert-success" role="alert"><strong>'.$weather.'</strong></div>' ;
}
else if($error){
echo '<div class="alert alert-danger" role="alert"><strong>The entered city not found !</strong></div>' ;
}
?>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
<script>
</script>
</body>
</html>