How to get Weather Information in PHP

How to get Weather Information in PHP

March 15, 2016

Would you like to implement functionality of Getting Weather Information in PHP? Try Below Code.

<?php

//Note: appid can be obtained after login on http://api.openweathermap.org

$city="indore";

$country="in";

// By City Name

//$url="http://api.openweathermap.org/data/2.5/weather?q=".$city.",".$country."&appid=b1b15e88fa797225412429c1c50c122a";

// By latitude & longitude

$url="http://api.openweathermap.org/data/2.5/weather?lat=22&lon=75&appid=b1b15e88fa797225412429c1c50c122a";

$json=file_get_contents($url);

$data=json_decode($json,true);

//Get current Temperature in Celsius

$kel=$data['main']['temp'];

$cel=$kel-273.15;

echo 'Celsious= '.$cel;

//Get current Temperature in Farenhite

$f=((($kel*9)/5)-459.67);

echo '<br>Farenhite='.$f;

?>

 

Related Posts

from my blog


Codelobster IDE – Powerful & Free PHP, HTML, CSS Editor

January 30, 2025

Codelobster IDE allows you to edit PHP, HTML, CSS, and JavaScript files, highlighting syntax and providing hints for tags, functions, and their parameters. This editor can simply deal with files...

How Much Money Can Freelance Web Developers Earn?

January 10, 2025

Freelance web developer is an exciting career path that gives you flexibility, creativity, and the potential to earn a high income. However, how much can a freelance web developer earn?...

Best Code Editor Solutions for Every Developer in 2021: The Ultimate Guide

August 20, 2021

Introduction: The life of a developer is no more than a roller coaster. They have to play codes with every single minute, which is not a handy thing. It requires...