<!DOCTYPE html>
<html>
<head>
  <title>PHP parsing a JSON file</title>
<style>
body {
    background: #fff;
    margin-top: 60px;
    margin-left: 40px;
    background-size: cover;
    font-family: Ariel, Verdana, sans-serif;
    font-size: 28px;
  }
</style>
</head>
<body>
<div class="image" style="background:url('clouds.jpg');width:720px;height:379px;">
<?php

$jsondata = 'https://api.openweathermap.org/data/2.5/weather?zip=10004,US&appid=a8e77dc963e712d4be9be394187b948f';
$json_string = file_get_contents($jsondata);
//print $json_string;
echo "<br>-------------------------<br>";

print "The current weather condition in New York is: ";

// Search substring
$key1 = 'description';
$key2 ='icon';

$strLoc1 = strpos($json_string, $key1);
//echo "First string position is: ";
//echo $strLoc1;
//echo "<br>";
$strLoc2 = strpos($json_string, $key2);
//echo "Second string position is: ";
$keyOffset = 17;
$exString = ($strLoc2 - $strLoc1);
$jsSubStr =  substr($json_string,($strLoc1 + 14), ($exString-$keyOffset));
//echo "<br>";
echo $jsSubStr;
echo "<br><br>";
$keyA = 'feels_like';
$keyB ='temp_min';
$strLocA = strpos($json_string, $keyA);
// echo "First string position is: ";
// echo $strLocA;
// echo "<br>";
$strLocB = strpos($json_string, $keyB);
// echo "Second string position is: ";
// echo $strLocB;
$kOffset = 14;
$xString = ($strLocB - $strLocA);
$jsSubString =  substr($json_string,($strLocA + 12), ($xString-$kOffset));
// echo "<br>";
//echo $jsSubString; // This is the temperature in Kelvin units
echo "<br>";
$float = floatval($jsSubString);
$tempC = ($float - 273.15);     // temperature Celsius
$tempF = (($tempC * 1.8) + 32);  // temperature Fahrenheit
print "The temperature feels like: ";
print $tempF . "(Fahrenheit)";
print "<br> Temperature Celsius: ";
echo $tempC;
echo "<br>-------------------------<br>";
?>
</div>

</body>
</html>
