Thursday, April 19, 2007

Getting weather in PHP

Just a quick tip how to get weather from weather.gov using their SOAP WSDL weather service. You will need to know the latitude and longitude of the place you are getting weather for.

First, make sure you have the --enable-soap extension installed.

Then it is just two lines of code:

$client = new SoapClient('http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgen');

$result = $client->NDFDgen(40.7893,-96.6938,'glance','2007-04-20T00:00','2007-04-21T00:00',NULL);

More information here:

http://www.nws.noaa.gov/forecasts/xml/