Skip to content

Commit

Permalink
json object decode and data display
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Mat committed May 9, 2018
1 parent fda2ecc commit bfb3b04
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions 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.