Get Weather Report in php and json using openweathermap Api


hello everybody what is up, today I am back with my new tutorial that how to get the Weather Report in PHP and JSON using the Openweathermap.org API, so as you all have seen the apple weather app and it uses the weather channel API for their Weather report to get the data for the weather so in this tutorial I am showing how to built something like that.

Demo Download Subscribe on Youtube

So let’s get started,

What is an API?

It’s an Application Programming Interface which allows users to fetch and display the data on their website. It can be anything like users information like facebook does and many other websites like google, LinkedIn also provide.

So in this tutorial, I am going to show how we can fetch weather report using openweathermap API so that we can display the results on our website using PHP.

What’s This Application Does?

It’s an application that simply uses a URL and pass the data through it, so for working with openweathermap API we need to pass the special key provided by them which you can easily find by registering on their website

Parameters we need to pass are

  • city or place name
  • key

That’s it.

So let’s take a look at the source codes and one thing I tell you that in this tutorial we are not going to use database just fetching the result directly from the openweathermap website using the PHP function get_file_contents

and decoding the URL into an array using the PHP function json_decode.

So here is the Index.php file.

And the form will be submitted on the Get.php file

So that’s it there is only 2 pages of source codes in this tutorial.

And if you have any problem using this API then you can see the detailed video here –

Please subscribe to the blog if you really like the tutorial and also do subscribe to my Youtube channel.

Thanks and I see you next time.