-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.php
More file actions
46 lines (33 loc) · 1.32 KB
/
Copy pathweather.php
File metadata and controls
46 lines (33 loc) · 1.32 KB
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
<?php
function getWeather ($location) {
$numOfDays = 2;
$APIkey = ""; // Put you API key here
$url = "http://free.worldweatheronline.com/feed/weather.ashx?key=" . $APIkey . "&q=" . $location . "&num_of_days=2&format=json";
$json_string = file_get_contents($url);
$json = json_decode($json_string);
return "Now: " . $json->data->current_condition[0]->weatherDesc[0]->value . ", Temp: " . $json->data->current_condition[0]->temp_F . "ºF, Tomorrow: " . $json->data->weather[1]->weatherDesc[0]->value . ", Tempe: " . $json->data->weather[1]->tempMinF . "ºF to " . $json->data->weather[1]->tempMaxF . "ºF";
} // fuction getWeather
function weather($body){
$pieces = explode(",", $body);
if ((sizeof($pieces) == 1) && (preg_match("#[0-9]{5}#", $pieces[0]) ))
{
$msg = getWeather($pieces[0]);
}
else if (sizeof($pieces) == 2)
{
$pieces[0] = str_replace(" ", "+", $pieces[0]);
$pieces[1] = str_replace(" ", "+", $pieces[1]);
$msg = getWeather($pieces[0] . "," . $pieces[1]);
}
else {
$msg = "Please use correct structure: 'w zipcode' or 'w city,state'";
}
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<Response>";
echo "<Sms>";
echo $msg;
echo "</Sms>";
echo "</Response>";
}
?>