Permalink
Browse files

json object decode and data display

  • Loading branch information...
franciscof5 committed May 9, 2018
1 parent fda2ecc commit bfb3b043bd080908ac8caed9afbfbb3c7e6ac36e
Showing with 31 additions and 10 deletions.
  1. +31 −10 index.php
@@ -1,22 +1,43 @@
<?php
$city = $_GET['c1-t'];
if(!isset($city) || $city==NULL)
$city='London,uk';
?>
<!DOCTYPE html>
<html>
<head>
<title>Bravi Weather Simples</title>
<title>Bravi Weather Simple</title>
</head>
<body>
<h1>City Weather</h1>
<p>Check out any city weather. Write city name below:</p>
<form method="GET" name="c1" action="index.php">
<input type="text" name="c1-t">
<input type="submit" name="c1-s" value="verify">
</form>
<?php
$url = 'http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=808268433b2e03a5e15354526a3e7712';
$ch = curl_init($url);
#$fp = fopen("pagina_exemplo.txt", "w");
#curl_setopt($ch, CURLOPT_FILE, $fp);
#curl_setopt($ch, CURLOPT_HEADER, 0);
$url = 'http://api.openweathermap.org/data/2.5/weather?q='.$city.'&appid=808268433b2e03a5e15354526a3e7712';
#$ch = curl_init($url);
#$r=curl_exec($ch);
#$j=json_decode($r);
$r = file_get_contents($url);
$j = json_decode($r);
curl_exec($ch);
curl_close($ch);
#fclose($fp);
echo '<hr />';
echo 'City: '.$city;
echo '<br />';
echo 'Current main weather: '.$j->weather[0]->main;
echo '<br />';
echo 'Description: '.$j->weather[0]->description;
echo '<br />';
echo 'Temperature: '.$j->main->temp." °F";
echo "teste";
?>
<p>Author: Francisco Matelli Matulovic</p>
<p>Released under GNU GPLv3</p>
</body>
</html>

0 comments on commit bfb3b04

Please sign in to comment.