Hi Guys,
I thought I should share goodies like this with you. There are many a times when we are doing a website for our client and they want to display local weather in the header of their website.
That’s cool thought but how do we do it in PHP.
Its really simple stuff.
Let me show you how
Google weather API can be accessed from this URL
http://www.google.com/ig/api
This is good, the only param you will need is called weather so the above URL will become
http://www.google.com/ig/api?weather=Melbourne
Try to browse above URL and you will get something like this

Alright that looks cool now lets get some key values from the above XML using PHP
with PHP you’ll do something like this
// get current condition echo($information[0]->condition->attributes())."<br>"; // get current temperature in Fahrenheit echo($information[0]->temp_f->attributes())."<br>"; // get current temperature in Celsius echo($information[0]->temp_c->attributes())."<br>"; // get current temperature in Celsius echo("<img src='$information[0]->icon->attributes()'>")."<br>"; } else { echo "Invalid address"; }
As you can see that its pretty easy to get that sort of info.
I hope this helps in some way or another
Cheers
Advertisement





JC WordPress Coupon Revealer Plugin Pro License
Australian Street Names with City, State and Display Names only, Single Server License
Recent Comments